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>
This commit is contained in:
Matt Bogosian 2022-03-10 08:42:15 -06:00 committed by GitHub
parent 9b51fd5d13
commit 32bf359792
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 7 deletions

View file

@ -5793,6 +5793,27 @@ class ParamSpecTests(BaseTestCase):
self.assertEqual(G2[[int, str], float], list[C])
self.assertEqual(G3[[int, str], float], list[C] | int)
def test_paramspec_gets_copied(self):
# bpo-46581
P = ParamSpec('P')
P2 = ParamSpec('P2')
C1 = Callable[P, int]
self.assertEqual(C1.__parameters__, (P,))
self.assertEqual(C1[P2].__parameters__, (P2,))
self.assertEqual(C1[str].__parameters__, ())
self.assertEqual(C1[str, T].__parameters__, (T,))
self.assertEqual(C1[Concatenate[str, P2]].__parameters__, (P2,))
self.assertEqual(C1[Concatenate[T, P2]].__parameters__, (T, P2))
self.assertEqual(C1[...].__parameters__, ())
C2 = Callable[Concatenate[str, P], int]
self.assertEqual(C2.__parameters__, (P,))
self.assertEqual(C2[P2].__parameters__, (P2,))
self.assertEqual(C2[str].__parameters__, ())
self.assertEqual(C2[str, T].__parameters__, (T,))
self.assertEqual(C2[Concatenate[str, P2]].__parameters__, (P2,))
self.assertEqual(C2[Concatenate[T, P2]].__parameters__, (T, P2))
class ConcatenateTests(BaseTestCase):
def test_basics(self):