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:
Miss Islington (bot) 2020-12-14 14:33:27 -08:00 committed by GitHub
parent 20bc40ef44
commit dbb00062dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View file

@ -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,)