mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-42059: Fix required/optional keys for TypedDict(..., total=False) (GH-22736) (GH-23747)
(cherry picked from commit 67b769f515
)
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
This commit is contained in:
parent
20bc40ef44
commit
dbb00062dc
3 changed files with 7 additions and 2 deletions
|
@ -1987,14 +1987,14 @@ def TypedDict(typename, fields=None, /, *, total=True, **kwargs):
|
|||
raise TypeError("TypedDict takes either a dict or keyword arguments,"
|
||||
" but not both")
|
||||
|
||||
ns = {'__annotations__': dict(fields), '__total__': total}
|
||||
ns = {'__annotations__': dict(fields)}
|
||||
try:
|
||||
# Setting correct module is necessary to make typed dict classes pickleable.
|
||||
ns['__module__'] = sys._getframe(1).f_globals.get('__name__', '__main__')
|
||||
except (AttributeError, ValueError):
|
||||
pass
|
||||
|
||||
return _TypedDictMeta(typename, (), ns)
|
||||
return _TypedDictMeta(typename, (), ns, total=total)
|
||||
|
||||
_TypedDict = type.__new__(_TypedDictMeta, 'TypedDict', (), {})
|
||||
TypedDict.__mro_entries__ = lambda bases: (_TypedDict,)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue