Skip to content
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
5 changes: 3 additions & 2 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,14 +1058,15 @@ class C(B[int]):
self.assertEqual(x.bar, 'abc')
self.assertEqual(x.__dict__, {'foo': 42, 'bar': 'abc'})
samples = [Any, Union, Tuple, Callable, ClassVar,
Union[int, str], ClassVar[List], Tuple[int, ...], Callable[[str], bytes]]
Union[int, str], ClassVar[List], Tuple[int, ...], Callable[[str], bytes],
typing.DefaultDict, typing.FrozenSet[int]]
for s in samples:
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
z = pickle.dumps(s, proto)
x = pickle.loads(z)
self.assertEqual(s, x)
more_samples = [List, typing.Iterable, typing.Type, List[int],
typing.Type[typing.Mapping]]
typing.Type[typing.Mapping], typing.AbstractSet[Tuple[int, str]]]
for s in more_samples:
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
z = pickle.dumps(s, proto)
Expand Down
15 changes: 14 additions & 1 deletion Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,19 @@ def __reduce__(self):
# * __args__ is a tuple of all arguments used in subscripting,
# e.g., Dict[T, int].__args__ == (T, int).


# Mapping from non-generic type names that have a generic alias in typing
# but with a different name.
_normalize_alias = {'list': 'List',
'tuple': 'Tuple',
'dict': 'Dict',
'set': 'Set',
'frozenset': 'FrozenSet',
'deque': 'Deque',
'defaultdict': 'DefaultDict',
'type': 'Type',
'Set': 'AbstractSet'}

def _is_dunder(attr):
return attr.startswith('__') and attr.endswith('__')

Expand All @@ -629,7 +642,7 @@ def __init__(self, origin, params, *, inst=True, special=False, name=None):
self._special = special
if special and name is None:
orig_name = origin.__name__
name = orig_name[0].title() + orig_name[1:]
name = _normalize_alias.get(orig_name, orig_name)
self._name = name
if not isinstance(params, tuple):
params = (params,)
Expand Down