]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43224: Add TypeVarTuple.__name__ (GH-31954)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Fri, 18 Mar 2022 17:56:36 +0000 (10:56 -0700)
committerGitHub <noreply@github.com>
Fri, 18 Mar 2022 17:56:36 +0000 (10:56 -0700)
I noticed that TypeVar and ParamSpec put their name in a __name__
attribute, but TypeVarTuple doesn't. Let's be consistent.

Lib/test/test_typing.py
Lib/typing.py

index bcffdc882dbe682e9cf7321574a89fc9948d98a2..0e28655296d14f16dc9729289d1aabf7a62dfd00 100644 (file)
@@ -415,6 +415,12 @@ class TypeVarTupleTests(BaseTestCase):
         if not string.endswith(tail):
             self.fail(f"String {string!r} does not end with {tail!r}")
 
+    def test_name(self):
+        Ts = TypeVarTuple('Ts')
+        self.assertEqual(Ts.__name__, 'Ts')
+        Ts2 = TypeVarTuple('Ts2')
+        self.assertEqual(Ts2.__name__, 'Ts2')
+
     def test_instance_is_equal_to_itself(self):
         Ts = TypeVarTuple('Ts')
         self.assertEqual(Ts, Ts)
@@ -509,15 +515,6 @@ class TypeVarTupleTests(BaseTestCase):
         self.assertEqual(repr(Unpack[tuple[Unpack[Ts]]]), '*tuple[*Ts]')
         self.assertEqual(repr(Unpack[Tuple[Unpack[Ts]]]), '*typing.Tuple[*Ts]')
 
-    def test_repr_is_correct(self):
-        Ts = TypeVarTuple('Ts')
-        self.assertEqual(repr(Ts), 'Ts')
-        self.assertEqual(repr(Unpack[Ts]), '*Ts')
-        self.assertEqual(repr(tuple[Unpack[Ts]]), 'tuple[*Ts]')
-        self.assertEqual(repr(Tuple[Unpack[Ts]]), 'typing.Tuple[*Ts]')
-        self.assertEqual(repr(Unpack[tuple[Unpack[Ts]]]), '*tuple[*Ts]')
-        self.assertEqual(repr(Unpack[Tuple[Unpack[Ts]]]), '*typing.Tuple[*Ts]')
-
     def test_variadic_class_repr_is_correct(self):
         Ts = TypeVarTuple('Ts')
         class A(Generic[Unpack[Ts]]): pass
index e8613625c3044c27e201702bf17d16ead1050179..f0e84900d7f80abaa58b2624c422e6f704dded94 100644 (file)
@@ -939,13 +939,13 @@ class TypeVarTuple(_Final, _Immutable, _root=True):
     """
 
     def __init__(self, name):
-        self._name = name
+        self.__name__ = name
 
     def __iter__(self):
         yield Unpack[self]
 
     def __repr__(self):
-        return self._name
+        return self.__name__
 
     def __typing_subst__(self, arg):
         raise AssertionError