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

lenient_issubclass does not work for generic aliases #2399

Closed
3 tasks done
daviskirk opened this issue Feb 24, 2021 · 0 comments · Fixed by #2392
Closed
3 tasks done

lenient_issubclass does not work for generic aliases #2399

daviskirk opened this issue Feb 24, 2021 · 0 comments · Fixed by #2392
Labels
bug V1 Bug related to Pydantic V1.X

Comments

@daviskirk
Copy link
Contributor

daviskirk commented Feb 24, 2021

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

Bug

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.7.3
            pydantic compiled: False
                 install path: /home/user/pydantic/pydantic
               python version: 3.9.0 (default, Nov 15 2020, 14:28:56)  [GCC 7.3.0]
                     platform: Linux-5.4.0-65-generic-x86_64-with-glibc2.31
     optional deps. installed: ['devtools', 'dotenv', 'email-validator', 'typing-extensions']

Using lenient_issubclass breaks for GernicAlias types.
This is important in python >= 3.9 as the typing become the default for defining types.

Reproducible example:

from pydantic.utils import lenient_issubclass
from collections.abc import Mapping
# should not raise an error here:
assert lenient_issubclass(list[str], Mapping) is False

raises:

    if lenient_issubclass(param.annotation, Request):
    \lib\site-packages\pydantic\utils.py:151: in lenient_issubclass
    return isinstance(cls, type) and issubclass(cls, class_or_tuple)
    \lib\abc.py:102: in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
E   TypeError: issubclass() arg 1 must be a class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant