Serhiy Storchaka <[email protected]> added the comment:
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
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40397>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com