8000 GH-103699: Add `__orig_bases__` to various typing classes by adriangb · Pull Request #103698 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-103699: Add __orig_bases__ to various typing classes #103698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 23, 2023
Prev Previous commit
Next Next commit
Make call-based NamedTuples behave like call-based TypedDicts
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
  • Loading branch information
adriangb and AlexWaygood committed Apr 23, 2023
commit 4c9ee8ca0ea7c15a5ba906079dad688db6c1a847
8 changes: 6 additions & 2 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2962,7 +2962,9 @@ class Employee(NamedTuple):
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', (), {})

Expand Down Expand Up @@ -3107,7 +3109,9 @@ class body be required.
# 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,)
Expand Down
0