def getattr_or_subscribe(instance, name):
    """Get an attribute from a class instance or a value from a dictionary.

    :param dict|object instance:
    :param str name: name of attribute or dictionary key
    :return any:
    """
    try:
        return getattr(instance, name)
    except AttributeError:
        try:
            return instance[name]
        except (TypeError, KeyError):
            raise AttributeError(f"{instance!r} does not have an attribute or key named {name!r}.")