Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add __name__ and __qualname__ to _SpecialForm
  • Loading branch information
uriyyo committed Jul 19, 2021
commit 6872f961950236a3681479fdd8ce0fb583b3291a
12 changes: 12 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4501,6 +4501,7 @@ def test_no_isinstance(self):
class SpecialAttrsTests(BaseTestCase):
def test_special_attrs(self):
cls_to_check = (
# ABC classes
typing.AbstractSet,
typing.AsyncContextManager,
typing.AsyncGenerator,
Expand Down Expand Up @@ -4539,6 +4540,17 @@ def test_special_attrs(self):
typing.Tuple,
typing.Type,
typing.ValuesView,
# Special Forms
typing.Any,
typing.NoReturn,
typing.ClassVar,
typing.Final,
typing.Union,
typing.Optional,
typing.Literal,
typing.TypeAlias,
typing.Concatenate,
typing.TypeGuard,
)

for cls in cls_to_check:
Comment thread
uriyyo marked this conversation as resolved.
Expand Down
6 changes: 6 additions & 0 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ def __init__(self, getitem):
self._name = getitem.__name__
self.__doc__ = getitem.__doc__

def __getattr__(self, item):
if item in {'__name__', '__qualname__'}:
return self._name

raise AttributeError(item)

def __mro_entries__(self, bases):
raise TypeError(f"Cannot subclass {self!r}")

Expand Down