[Python-checkins] bpo-43224: Add TypeVarTuple.__name__ (GH-31954)
JelleZijlstra
webhook-mailer at python.org
Fri Mar 18 13:56:49 EDT 2022
https://github.com/python/cpython/commit/3a2b89580ded72262fbea0f7ad24096a90c42b9c
commit: 3a2b89580ded72262fbea0f7ad24096a90c42b9c
branch: main
author: Jelle Zijlstra <jelle.zijlstra at gmail.com>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2022-03-18T10:56:36-07:00
summary:
bpo-43224: Add TypeVarTuple.__name__ (GH-31954)
I noticed that TypeVar and ParamSpec put their name in a __name__
attribute, but TypeVarTuple doesn't. Let's be consistent.
files:
M Lib/test/test_typing.py
M Lib/typing.py
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index bcffdc882dbe6..0e28655296d14 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -415,6 +415,12 @@ def assertEndsWith(self, string, tail):
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 @@ def test_repr_is_correct(self):
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
diff --git a/Lib/typing.py b/Lib/typing.py
index e8613625c3044..f0e84900d7f80 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -939,13 +939,13 @@ class C(Generic[*Ts]): ...
"""
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
More information about the Python-checkins
mailing list