amino/tc/base.py
def lookup(self, TC: type, G: type) -> Optional[TypeClass]:
        ''' Find an instance of the type class `TC` for type `G`.
        Iterates `G`'s parent classes, looking up instances for each,
        checking whether the instance is a subclass of the target type
        class `TC`.
        '''
        if isinstance(G, str):
            raise ImplicitNotFound(TC, G, f'{G} is a string annotation')
        if not isinstance(G, (type, TypeVar, _GenericAlias)):
            raise ImplicitNotFound(TC, G, f'{G} is neither type, _GenericAlias nor TypeVar: {type(G)}')
        match = lambda a: self._lookup_type(TC, a)
        def attach_type(tc: TypeClass) -> TypeClass:
            setattr(tc, 'tpe', G)
            return tc
        scrutinee = (
            (
                unbounded_typevar(TC, G)
                if G.__bound__ is None else
                G.__bound__
            )
            if isinstance(G, TypeVar) else
            G
        )
        safe_mro = lambda t: getattr(t, '__mro__', (t,))
        target = scrutinee.__origin__ if isinstance(scrutinee, _GenericAlias) else scrutinee
        mro = safe_mro(target)
        return next((attach_type(a) for a in map(match, mro) if a is not None), None)
def lookup(self, TC: type, G: type) -> Optional[TypeClass]:
        ''' Find an instance of the type class `TC` for type `G`.
        Iterates `G`'s parent classes, looking up instances for each,
        checking whether the instance is a subclass of the target type
        class `TC`.
        '''
        if isinstance(G, str):
            raise ImplicitNotFound(TC, G, f'{G} is a string annotation')
        if not isinstance(G, (type, TypeVar, _GenericAlias)):
            raise ImplicitNotFound(TC, G, f'{G} is neither type, _GenericAlias nor TypeVar: {type(G)}')
        match = lambda a: self._lookup_type(TC, a)
        def attach_type(tc: TypeClass) -> TypeClass:
            setattr(tc, 'tpe', G)
            return tc
        scrutinee = (
            (
                unbounded_typevar(TC, G)
                if G.__bound__ is None else
                G.__bound__
            )
            if isinstance(G, TypeVar) else
            G
        )
        safe_mro = lambda t: getattr(t, '__mro__', (t,))
        target = scrutinee.__origin__ if isinstance(scrutinee, _GenericAlias) else scrutinee
        mro = safe_mro(target)
        return next((attach_type(a) for a in map(match, mro) if a is not None), None)
Find an instance of the type class `TC` for type `G`.
        Iterates `G`'s parent classes, looking up instances for each,
        checking whether the instance is a subclass of the target type
        class `TC`.