mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +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
|
|
@ -4990,6 +4990,27 @@ def test_paramspec_in_nested_generics(self):
|
|||
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