mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
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:
parent
9b51fd5d13
commit
32bf359792
4 changed files with 30 additions and 7 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue