Message367944
There is a difference between PR 19836 and the typing module in handling nested unsubscribed generic aliases:
>>> from typing import *
>>> T = TypeVar('T')
>>> D1 = Dict[T, List]
>>> D2 = dict[T, List]
>>> D1.__parameters__
(~T,)
>>> D1[int]
typing.Dict[int, typing.List[~T]]
>>> D1[int].__parameters__
(~T,)
>>> D1[int][str]
typing.Dict[int, typing.List[str]]
>>> D1[int, str]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/typing.py", line 267, in inner
return func(*args, **kwds)
File "/home/serhiy/py/cpython/Lib/typing.py", line 686, in __getitem__
_check_generic(self, params)
File "/home/serhiy/py/cpython/Lib/typing.py", line 221, in _check_generic
raise TypeError(f"Too {'many' if alen > elen else 'few'} parameters for {cls};"
TypeError: Too many parameters for typing.Dict[~T, typing.List]; actual 2, expected 1
>>> D2.__parameters__
(~T, ~T)
>>> D2[int]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Too few arguments for dict[~T, typing.List]
>>> D2[int, str]
dict[int, typing.List[str]]
But this behavior is not specified and is not covered by tests. |
|
Date |
User |
Action |
Args |
2020-05-02 18:03:40 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, gvanrossum, levkivskyi |
2020-05-02 18:03:40 | serhiy.storchaka | set | messageid: <1588442620.22.0.102911863717.issue40408@roundup.psfhosted.org> |
2020-05-02 18:03:40 | serhiy.storchaka | link | issue40408 messages |
2020-05-02 18:03:40 | serhiy.storchaka | create | |
|