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_subtype fails with List[TypeVar] #114

Open
betodealmeida opened this issue Jan 4, 2022 · 0 comments
Open

is_subtype fails with List[TypeVar] #114

betodealmeida opened this issue Jan 4, 2022 · 0 comments

Comments

@betodealmeida
Copy link

betodealmeida commented Jan 4, 2022

from typing import List, TypeVar
from pytypes import is_subtype

T = TypeVar("T")
is_subtype(List[int], List[T])

Fails with (Python 3.9):

Traceback (most recent call last):
  File "/Users/beto/Projects/datajunction/bug.py", line 5, in <module>
    is_subtype(List[int], List[T])
  File "/Users/beto/.pyenv/versions/dj/lib/python3.9/site-packages/pytypes/type_util.py", line 2738, in _issubclass
    res = _issubclass_2(
  File "/Users/beto/.pyenv/versions/dj/lib/python3.9/site-packages/pytypes/type_util.py", line 2814, in _issubclass_2
    return _issubclass_Generic(
  File "/Users/beto/.pyenv/versions/dj/lib/python3.9/site-packages/pytypes/type_util.py", line 1935, in _issubclass_Generic
    assert len(superclass.__args__) == len(prms)
AssertionError

And in 3.8:

Traceback (most recent call last):
  File "Projects/datajunction/src/datajunction/functions.py", line 89, in <module>
    print(infer_type("first", {"column": List[float]}) == float)
  File "Projects/datajunction/src/datajunction/functions.py", line 63, in infer_type
    if argument not in anno or not is_subtype(type_, anno[argument], type_):
  File "/Users/beto/.pyenv/versions/superset/lib/python3.8/site-packages/pytypes/type_util.py", line 2019, in _issubclass
    res = _issubclass_2(subclass, superclass, bound_Generic, bound_typevars,
  File "/Users/beto/.pyenv/versions/superset/lib/python3.8/site-packages/pytypes/type_util.py", line 2051, in _issubclass_2
    return _issubclass_Generic(subclass, superclass, bound_Generic, bound_typevars,
  File "/Users/beto/.pyenv/versions/superset/lib/python3.8/site-packages/pytypes/type_util.py", line 1582, in _issubclass_Generic
    if not _issubclass(p_self, p_cls, bound_Generic, bound_typevars,
  File "/Users/beto/.pyenv/versions/superset/lib/python3.8/site-packages/pytypes/type_util.py", line 2015, in _issubclass
    if not subclass.__bound__ is None:
AttributeError: 'NoneType' object has no attribute '__bound__'
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

1 participant