Skip to content

Commit 1b91e82

Browse files
committed
Add missed __name__ and __qualname__ to typing module objects
1 parent 2c20558 commit 1b91e82

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

Lib/test/test_typing.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4498,6 +4498,54 @@ def test_no_isinstance(self):
44984498
issubclass(int, TypeGuard)
44994499

45004500

4501+
class SpecialAttrsTests(BaseTestCase):
4502+
def test_special_attrs(self):
4503+
cls_to_check = (
4504+
typing.AbstractSet,
4505+
typing.AsyncContextManager,
4506+
typing.AsyncGenerator,
4507+
typing.AsyncIterable,
4508+
typing.AsyncIterator,
4509+
typing.Awaitable,
4510+
typing.ByteString,
4511+
typing.Callable,
4512+
typing.ChainMap,
4513+
typing.Collection,
4514+
typing.Container,
4515+
typing.ContextManager,
4516+
typing.Coroutine,
4517+
typing.Counter,
4518+
typing.DefaultDict,
4519+
typing.Deque,
4520+
typing.Dict,
4521+
typing.FrozenSet,
4522+
typing.Generator,
4523+
typing.Hashable,
4524+
typing.ItemsView,
4525+
typing.Iterable,
4526+
typing.Iterator,
4527+
typing.KeysView,
4528+
typing.List,
4529+
typing.Mapping,
4530+
typing.MappingView,
4531+
typing.MutableMapping,
4532+
typing.MutableSequence,
4533+
typing.MutableSet,
4534+
typing.OrderedDict,
4535+
typing.Reversible,
4536+
typing.Sequence,
4537+
typing.Set,
4538+
typing.Sized,
4539+
typing.Tuple,
4540+
typing.Type,
4541+
typing.ValuesView,
4542+
)
4543+
4544+
for cls in cls_to_check:
4545+
self.assertEqual(cls.__name__, cls._name)
4546+
self.assertEqual(cls.__qualname__, cls._name)
4547+
self.assertEqual(cls.__module__, 'typing')
4548+
45014549
class AllTests(BaseTestCase):
45024550
"""Tests for __all__."""
45034551

Lib/typing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,9 @@ def __mro_entries__(self, bases):
935935
return tuple(res)
936936

937937
def __getattr__(self, attr):
938+
if attr in {'__name__', '__qualname__'}:
939+
return self._name
940+
938941
# We are careful for copy and pickle.
939942
# Also for simplicity we just don't relay all dunder names
940943
if '__origin__' in self.__dict__ and not _is_dunder(attr):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add missed ``__name__`` and ``__qualname__`` attribute to ``typing`` module
2+
objects. Patch provided by Yurii Karabas.

0 commit comments

Comments
 (0)