diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-01-27 12:34:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 12:34:55 (GMT) |
commit | ecfacc362dd7fef7715dcd94f2e2ca6c622ef115 (patch) | |
tree | 3a907fea5ce2b03d03e7c6619e0cf12c4785d2cc /Lib/typing.py | |
parent | 82bce54614f8116a40454fbbbf96a3fd460ca7df (diff) | |
download | cpython-ecfacc362dd7fef7715dcd94f2e2ca6c622ef115.zip cpython-ecfacc362dd7fef7715dcd94f2e2ca6c622ef115.tar.gz cpython-ecfacc362dd7fef7715dcd94f2e2ca6c622ef115.tar.bz2 |
bpo-44791: Fix substitution of ParamSpec in Concatenate with different parameter expressions (GH-27518)
* Substitution with a list of types returns now a tuple of types.
* Substitution with Concatenate returns now a Concatenate with
concatenated lists of arguments.
* Substitution with Ellipsis is not supported.
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 450cd7b..36b95d7 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -604,7 +604,7 @@ def Concatenate(self, parameters): raise TypeError("The last parameter to Concatenate should be a " "ParamSpec variable.") msg = "Concatenate[arg, ...]: each arg must be a type." - parameters = tuple(_type_check(p, msg) for p in parameters) + parameters = (*(_type_check(p, msg) for p in parameters[:-1]), parameters[-1]) return _ConcatenateGenericAlias(self, parameters) @@ -1274,6 +1274,16 @@ class _ConcatenateGenericAlias(_GenericAlias, _root=True): _typevar_types=(TypeVar, ParamSpec), _paramspec_tvars=True) + def copy_with(self, params): + if isinstance(params[-1], (list, tuple)): + return (*params[:-1], *params[-1]) + if isinstance(params[-1], _ConcatenateGenericAlias): + params = (*params[:-1], *params[-1].__args__) + elif not isinstance(params[-1], ParamSpec): + raise TypeError("The last parameter to Concatenate should be a " + "ParamSpec variable.") + return super().copy_with(params) + class Generic: """Abstract base class for generic types. |