Message398688
> Type expression is coerced to a list of parameter arguments in substitution of ParamSpec.
It's not, only the repr is like that. Internally it's not coerced.
>>> C[int, str]
typing.Callable[[int], str]
>>> C[int, str].__args__
(<class 'int'>, <class 'str'>)
Because Callable's correct form is Callable[[type], type] (where type is not ParamSpec or Concatenate) so the repr reflects that.
Internally, Callable also flattens the list of args:
>>> Callable[[int, str], int].__args__
(<class 'int'>, <class 'str'>, <class 'int'>)
Because __args__ *must* be hashable and immutable. Otherwise, it will not work with Union or Literal. Some time ago we tried converting to nested tuple. But that was too difficult (and backwards incompatible) because every other typing operation expected __args__ to contain types, not a tuple. |
|
Date |
User |
Action |
Args |
2021-08-01 07:55:02 | kj | set | recipients:
+ kj, gvanrossum, serhiy.storchaka |
2021-08-01 07:55:02 | kj | set | messageid: <1627804502.89.0.296522722542.issue44801@roundup.psfhosted.org> |
2021-08-01 07:55:02 | kj | link | issue44801 messages |
2021-08-01 07:55:02 | kj | create | |
|