Message368367
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 |
|
Date |
User |
Action |
Args |
2020-05-07 18:44:00 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, gvanrossum, levkivskyi |
2020-05-07 18:44:00 | serhiy.storchaka | set | messageid: <1588877040.39.0.797830764866.issue40397@roundup.psfhosted.org> |
2020-05-07 18:44:00 | serhiy.storchaka | link | issue40397 messages |
2020-05-07 18:44:00 | serhiy.storchaka | create | |
|