Skip to content

is_of_type does not work as expected with Annotated[Generic[T], ...] #102

@phubaba

Description

@phubaba

Note this is in python 3.9 where typing.Annotated exists. I'm using pytypes from
pip install git+https://github.com/Stewori/pytypes.git

import pytypes
import typing
CT = typing.TypeVar('CT')
class Variable(typing.Generic[CT]):
    pass
pytypes.is_of_type(Variable[int](), Variable[int]) # returns True as expected
pytypes.is_of_type(Variable[int](), typing.Annotated[Variable[int], 'a']) # returns False unexpected

pytypes.is_of_type(3, typing.Annotated[int, 'a']) # returns True as expected

After stepping through the is_of_type function I end up in _issubclass_Generic.
I suspect there is some issue in _issubclass_Generic here:

          elif origin is not None and \
                  _issubclass(_origin(subclass), origin, bound_Generic, bound_typevars,
                          bound_typevars_readonly, follow_fwd_refs, _recursion_check):

takes an origin of the subclass so Variable[int] turns into Variable and origin of typing.Annotated is Variable[Int] so clearly _issubclass(Variable, Variable[int]) will not go through later parts of the function will basically all return False, so I think this is the place that needs to work.

Anyways let me know if I can be of any more help in resolving this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions