Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
phubaba opened this issue Jun 16, 2021 · 1 comment
Open

Comments

@phubaba
Copy link

phubaba commented Jun 16, 2021

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.

@Stewori
Copy link
Owner

Stewori commented Jun 16, 2021

Please note that Python 3.9 is not supported at the moment. Also 3.7 and 3.8 are not fully supported (but mostly), see #40 and #99. If you can make this particular issue work, feel free to do it (PR welcome). However, I suspect a broader 3.9 support would be a larger effort, which I currently cannot afford. (Changes in typing between 3.8 and 3.9 were manifold)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants