[issue45438] inspect not capturing type annotations created by __class_getitem__

Serhiy Storchaka report at bugs.python.org
Mon Oct 25 12:08:38 EDT 2021


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

Two years is not so long for a bug. We fixed 8-year and 12-year bugs.

The issue is that this feature is internally inconsistent (isinstance() is not consistent with issubclass()), the C implementation of list[int] is not consistent with the Python implementation of List[int], and a lot of code was not tested with this feature, so we perhaps have a lot of bugs in the stdlib and in the third-party libraries. Are we going to backport changes for making code working with GenericAlias as a type to 3.9 and 3.10? If not, we will actually add new features in 3.11 and keep 3.9 and 3.10 broken. If yes, these changes can have larger effect than just making isinstance(list[int], type) returning False, and they can break more code.

Note also that isinstance(List[int], type) was True before 3.7, and we intentionally made it False in 3.7 (it was required significant rewriting of the typing module and introducing __mro_entries__). Do we want to revert this decision?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45438>
_______________________________________


More information about the Python-bugs-list mailing list