This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients gvanrossum, kj, levkivskyi, rhettinger, serhiy.storchaka
Date 2021-10-13.11:54:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634126099.57.0.58909911192.issue45438@roundup.psfhosted.org>
In-reply-to
Content
The cause is that isinstance(list[int], type) returns True. It can cause bugs in other parts of the code which test for instance of type. For example:

>>> types.resolve_bases((typing.List[int],))
(<class 'list'>, <class 'typing.Generic'>)
>>> types.resolve_bases((list[int],))
(list[int],)

>>> types.prepare_class('A', (int,), {'metaclass': typing.Type[int]})
(typing.Type[int], {}, {})
>>> types.prepare_class('A', (int,), {'metaclass': type[int]})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython/Lib/types.py", line 125, in prepare_class
    meta = _calculate_meta(meta, bases)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/types.py", line 139, in _calculate_meta
    if issubclass(base_meta, winner):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: issubclass() argument 2 cannot be a parameterized generic

>>> @functools.singledispatch
... def g(a): pass
... 
>>> @g.register
... def g2(a: typing.List[int]): pass
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/serhiy/py/cpython/Lib/functools.py", line 863, in register
    raise TypeError(
    ^^^^^^^^^^^^^^^^
TypeError: Invalid annotation for 'a'. typing.List[int] is not a class.
>>> @g.register(list[int])
... def g2(a): pass
... 
>>> @g.register
... def g3(a: typing.List[int]): pass
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/serhiy/py/cpython/Lib/functools.py", line 863, in register
    raise TypeError(
    ^^^^^^^^^^^^^^^^
TypeError: Invalid annotation for 'a'. typing.List[int] is not a class.
>>> @g.register
... def g3(a: list[int]): pass
... 

And many other examples, too many to show here.

Was it mistake to make isinstance(list[int], type) returning True?
History
Date User Action Args
2021-10-13 11:54:59serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, rhettinger, levkivskyi, kj
2021-10-13 11:54:59serhiy.storchakasetmessageid: <1634126099.57.0.58909911192.issue45438@roundup.psfhosted.org>
2021-10-13 11:54:59serhiy.storchakalinkissue45438 messages
2021-10-13 11:54:59serhiy.storchakacreate