bpo-44524: Add missed __name__ and __qualname__ to typing module obje… · python/cpython@c895f2b · GitHub
Skip to content

Commit c895f2b

Browse files
bpo-44524: Add missed __name__ and __qualname__ to typing module objects (GH-27237) (#27246)
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit bce1418) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.com>
1 parent 8c43bf1 commit c895f2b

3 files changed

Lines changed: 72 additions & 0 deletions

File tree

Lib/test/test_typing.py

Lines changed: 61 additions & 0 deletions

Lib/typing.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,12 @@ def __init__(self, getitem):
357357
self._name = getitem.__name__
358358
self.__doc__ = getitem.__doc__
359359

360+
def __getattr__(self, item):
361+
if item in {'__name__', '__qualname__'}:
362+
return self._name
363+
364+
raise AttributeError(item)
365+
360366
def __mro_entries__(self, bases):
361367
raise TypeError(f"Cannot subclass {self!r}")
362368

@@ -934,6 +940,9 @@ def __mro_entries__(self, bases):
934940
return tuple(res)
935941

936942
def __getattr__(self, attr):
943+
if attr in {'__name__', '__qualname__'}:
944+
return self._name
945+
937946
# We are careful for copy and pickle.
938947
# Also for simplicity we just don't relay all dunder names
939948
if '__origin__' in self.__dict__ and not _is_dunder(attr):
Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)