diff options
author | Matt Bogosian <matt@bogosian.net> | 2022-03-10 14:42:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-10 14:42:15 (GMT) |
commit | 32bf3597922ac3f613989582afa2bff43bea8a2f (patch) | |
tree | 021eab024d0936c9e682af8adebdf1123d83f0e1 /Lib/typing.py | |
parent | 9b51fd5d137b662c940f072297b30815f37f105b (diff) | |
download | cpython-32bf3597922ac3f613989582afa2bff43bea8a2f.zip cpython-32bf3597922ac3f613989582afa2bff43bea8a2f.tar.gz cpython-32bf3597922ac3f613989582afa2bff43bea8a2f.tar.bz2 |
bpo-46581: Propagate private vars via _GenericAlias.copy_with (GH-31061)
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>
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index abb8bce..e301556 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -670,7 +670,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 @@ -1339,7 +1341,9 @@ class _GenericAlias(_BaseGenericAlias, _root=True): return tuple(new_args) def copy_with(self, args): - return self.__class__(self.__origin__, args, name=self._name, inst=self._inst) + return self.__class__(self.__origin__, args, name=self._name, inst=self._inst, + _typevar_types=self._typevar_types, + _paramspec_tvars=self._paramspec_tvars) def __repr__(self): if self._name: @@ -1548,11 +1552,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]) |