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, levkivskyi, serhiy.storchaka
Date 2020-05-07.18:44:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1588877040.39.0.797830764866.issue40397@roundup.psfhosted.org>
In-reply-to
Content
The next PR removes __args__ and __parameters__ from _SpecialGenericAlias.

* No existing test is failed. It is an evidence that these attributes are not intended, but a side effect of mixing two different kinds in one class.

* get_args() ignores __args__ and returns () for _SpecialGenericAlias (after resolving issue40398).

* Nested _SpecialGenericAlias is not considered a generic class containing type variables:

>>> from typing import *
>>> T = TypeVar('T')
>>> Dict[int, List[T]][str]
typing.Dict[int, typing.List[str]]
>>> Dict[int, List][str]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython-release/Lib/typing.py", line 244, in inner
    return func(*args, **kwds)
  File "/home/serhiy/py/cpython-release/Lib/typing.py", line 695, in __getitem__
    _check_generic(self, params)
  File "/home/serhiy/py/cpython-release/Lib/typing.py", line 194, in _check_generic
    raise TypeError(f"{cls} is not a generic class")
TypeError: typing.Dict[int, typing.List] is not a generic class

It also fixes the following error:

>>> from typing import *
>>> T = TypeVar('T')
>>> Dict[T, List][str]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython-release/Lib/typing.py", line 241, in inner
    return cached(*args, **kwds)
  File "/home/serhiy/py/cpython-release/Lib/typing.py", line 703, in __getitem__
    subargs = tuple(subst[x] for x in arg.__parameters__)
  File "/home/serhiy/py/cpython-release/Lib/typing.py", line 703, in <genexpr>
    subargs = tuple(subst[x] for x in arg.__parameters__)
KeyError: ~T

and allows to simplify __eq__ and __hash__ for _SpecialGenericAlias. Currently it has a weird behavior in corner case:

>>> from typing import *
>>> from typing import T
>>> List == List[T]
True
History
Date User Action Args
2020-05-07 18:44:00serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, levkivskyi
2020-05-07 18:44:00serhiy.storchakasetmessageid: <1588877040.39.0.797830764866.issue40397@roundup.psfhosted.org>
2020-05-07 18:44:00serhiy.storchakalinkissue40397 messages
2020-05-07 18:44:00serhiy.storchakacreate