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
48 changes: 48 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4498,6 +4498,54 @@ def test_no_isinstance(self):
issubclass(int, TypeGuard)


class SpecialAttrsTests(BaseTestCase):
def test_special_attrs(self):
cls_to_check = (
typing.AbstractSet,
typing.AsyncContextManager,
typing.AsyncGenerator,
typing.AsyncIterable,
typing.AsyncIterator,
typing.Awaitable,
typing.ByteString,
typing.Callable,
typing.ChainMap,
typing.Collection,
typing.Container,
typing.ContextManager,
typing.Coroutine,
typing.Counter,
typing.DefaultDict,
typing.Deque,
typing.Dict,
typing.FrozenSet,
typing.Generator,
typing.Hashable,
typing.ItemsView,
typing.Iterable,
typing.Iterator,
typing.KeysView,
typing.List,
typing.Mapping,
typing.MappingView,
typing.MutableMapping,
typing.MutableSequence,
typing.MutableSet,
typing.OrderedDict,
typing.Reversible,
typing.Sequence,
typing.Set,
typing.Sized,
typing.Tuple,
typing.Type,
typing.ValuesView,
)

for cls in cls_to_check:
Comment thread
uriyyo marked this conversation as resolved.
self.assertEqual(cls.__name__, cls._name)
self.assertEqual(cls.__qualname__, cls._name)
self.assertEqual(cls.__module__, 'typing')

class AllTests(BaseTestCase):
"""Tests for __all__."""

Expand Down
3 changes: 3 additions & 0 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,9 @@ def __mro_entries__(self, bases):
return tuple(res)

def __getattr__(self, attr):
if attr in {'__name__', '__qualname__'}:
return self._name
Comment thread
uriyyo marked this conversation as resolved.

# We are careful for copy and pickle.
# Also for simplicity we just don't relay all dunder names
if '__origin__' in self.__dict__ and not _is_dunder(attr):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add missed ``__name__`` and ``__qualname__`` attribute to ``typing`` module
objects. Patch provided by Yurii Karabas.
Comment thread
uriyyo marked this conversation as resolved.
Outdated