diff options
author | Ivan Levkivskyi <levkivskyi@gmail.com> | 2018-04-05 00:25:15 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-05 00:25:15 (GMT) |
commit | 2a363d2930e29ec6d8a774973ed5a4965f881f5f (patch) | |
tree | ed4bc9f9723c14f810e0b7b7dd5496c9226c0b47 /Lib/typing.py | |
parent | ee566fe526f3d069aa313578ee81ca6cbc25ff52 (diff) | |
download | cpython-2a363d2930e29ec6d8a774973ed5a4965f881f5f.zip cpython-2a363d2930e29ec6d8a774973ed5a4965f881f5f.tar.gz cpython-2a363d2930e29ec6d8a774973ed5a4965f881f5f.tar.bz2 |
bpo-32873: Remove a name hack for generic aliases in typing module (GH-6376)
This removes a hack and replaces it with a proper
mapping {'list': 'List', 'dict': 'Dict', ...}.
Diffstat (limited to 'Lib/typing.py')
-rw-r--r-- | Lib/typing.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 3ac3b93..d45502f 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -611,6 +611,19 @@ class TypeVar(_Final, _Immutable, _root=True): # * __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('__') @@ -629,7 +642,7 @@ class _GenericAlias(_Final, _root=True): 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,) |