mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
This commit is contained in:
parent
82bce54614
commit
ecfacc362d
4 changed files with 65 additions and 5 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue