mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
[3.10] bpo-46581: Propagate private vars via _GenericAlias.copy_with (GH-31061) (GH-31821)
(Cherry-picked from 32bf359792
.)
GH-26091 added the _typevar_types and _paramspec_tvars instance
variables to _GenericAlias. However, they were not propagated
consistently. This commit addresses the most prominent deficiency
identified in bpo-46581 (namely their absence from
_GenericAlias.copy_with), but there could be others.
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
4199b7ffbb
commit
3bc8019606
4 changed files with 30 additions and 7 deletions
|
@ -600,7 +600,9 @@ def Concatenate(self, parameters):
|
|||
"ParamSpec variable.")
|
||||
msg = "Concatenate[arg, ...]: each arg must be a type."
|
||||
parameters = (*(_type_check(p, msg) for p in parameters[:-1]), parameters[-1])
|
||||
return _ConcatenateGenericAlias(self, parameters)
|
||||
return _ConcatenateGenericAlias(self, parameters,
|
||||
_typevar_types=(TypeVar, ParamSpec),
|
||||
_paramspec_tvars=True)
|
||||
|
||||
|
||||
@_SpecialForm
|
||||
|
@ -1079,7 +1081,9 @@ class _GenericAlias(_BaseGenericAlias, _root=True):
|
|||
return self.copy_with(tuple(new_args))
|
||||
|
||||
def copy_with(self, params):
|
||||
return self.__class__(self.__origin__, params, name=self._name, inst=self._inst)
|
||||
return self.__class__(self.__origin__, params, name=self._name, inst=self._inst,
|
||||
_typevar_types=self._typevar_types,
|
||||
_paramspec_tvars=self._paramspec_tvars)
|
||||
|
||||
def __repr__(self):
|
||||
if self._name:
|
||||
|
@ -1281,11 +1285,6 @@ class _LiteralGenericAlias(_GenericAlias, _root=True):
|
|||
|
||||
|
||||
class _ConcatenateGenericAlias(_GenericAlias, _root=True):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs,
|
||||
_typevar_types=(TypeVar, ParamSpec),
|
||||
_paramspec_tvars=True)
|
||||
|
||||
def copy_with(self, params):
|
||||
if isinstance(params[-1], (list, tuple)):
|
||||
return (*params[:-1], *params[-1])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue