From aac15f80c2ad5359986a372aa41a648ee60bc413 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 16 Mar 2022 21:09:47 -0700 Subject: [PATCH 1/2] bpo-43224: Add TypeVarTuple.__name__ 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 | 6 ++++++ Lib/typing.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index e88f7322b2fa85..dd7a51e09a293c 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) diff --git a/Lib/typing.py b/Lib/typing.py index 6930f5ddac42ac..a280db4f82dc17 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 From da0ca6dbfd6aa1c1dc4dd03c59852e608f4c9ea9 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 16 Mar 2022 22:43:14 -0700 Subject: [PATCH 2/2] remove duplicate test --- Lib/test/test_typing.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index dd7a51e09a293c..052d5b5f7909a4 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -517,15 +517,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