Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-43224: Add TypeVarTuple.__name__ #31954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -511,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):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed this is the same as the function above.

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
Expand Down
4 changes: 2 additions & 2 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down