summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorAdrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>2023-04-23 14:33:39 (GMT)
committerGitHub <noreply@github.com>2023-04-23 14:33:39 (GMT)
commit0056701aa370553636b676cc99e327137d1688c6 (patch)
tree1c763864e27a1467257265422c490143b49d1040 /Lib/typing.py
parente38bebb9ee805df6848f42845e71c8da8a821ad3 (diff)
downloadcpython-0056701aa370553636b676cc99e327137d1688c6.zip
cpython-0056701aa370553636b676cc99e327137d1688c6.tar.gz
cpython-0056701aa370553636b676cc99e327137d1688c6.tar.bz2
GH-103699: Add `__orig_bases__` to various typing classes (#103698)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 7c16556..354bc80 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -2962,7 +2962,9 @@ def NamedTuple(typename, fields=None, /, **kwargs):
elif kwargs:
raise TypeError("Either list of fields or keywords"
" can be provided to NamedTuple, not both")
- return _make_nmtuple(typename, fields, module=_caller())
+ nt = _make_nmtuple(typename, fields, module=_caller())
+ nt.__orig_bases__ = (NamedTuple,)
+ return nt
_NamedTuple = type.__new__(NamedTupleMeta, 'NamedTuple', (), {})
@@ -2994,6 +2996,9 @@ class _TypedDictMeta(type):
tp_dict = type.__new__(_TypedDictMeta, name, (*generic_base, dict), ns)
+ if not hasattr(tp_dict, '__orig_bases__'):
+ tp_dict.__orig_bases__ = bases
+
annotations = {}
own_annotations = ns.get('__annotations__', {})
msg = "TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a type"
@@ -3104,7 +3109,9 @@ def TypedDict(typename, fields=None, /, *, total=True, **kwargs):
# Setting correct module is necessary to make typed dict classes pickleable.
ns['__module__'] = module
- return _TypedDictMeta(typename, (), ns, total=total)
+ td = _TypedDictMeta(typename, (), ns, total=total)
+ td.__orig_bases__ = (TypedDict,)
+ return td
_TypedDict = type.__new__(_TypedDictMeta, 'TypedDict', (), {})
TypedDict.__mro_entries__ = lambda bases: (_TypedDict,)