@@ -1618,9 +1618,11 @@ def __index__(self) -> int:
1618
1618
pass
1619
1619
1620
1620
1621
- if sys .version_info [: 2 ] >= (3 , 9 ):
1621
+ if sys .version_info >= (3 , 9 , 2 ):
1622
1622
# The standard library TypedDict in Python 3.8 does not store runtime information
1623
1623
# about which (if any) keys are optional. See https://bugs.python.org/issue38834
1624
+ # The standard library TypedDict in Python 3.9.0/1 does not honour the "total"
1625
+ # keyword with old-style TypedDict(). See https://bugs.python.org/issue42059
1624
1626
TypedDict = typing .TypedDict
1625
1627
else :
1626
1628
def _check_fails (cls , other ):
@@ -1677,19 +1679,24 @@ def _typeddict_new(*args, total=True, **kwargs):
1677
1679
raise TypeError ("TypedDict takes either a dict or keyword arguments,"
1678
1680
" but not both" )
1679
1681
1680
- ns = {'__annotations__' : dict (fields ), '__total__' : total }
1682
+ ns = {'__annotations__' : dict (fields )}
1681
1683
try :
1682
1684
# Setting correct module is necessary to make typed dict classes pickleable.
1683
1685
ns ['__module__' ] = sys ._getframe (1 ).f_globals .get ('__name__' , '__main__' )
1684
1686
except (AttributeError , ValueError ):
1685
1687
pass
1686
1688
1687
- return _TypedDictMeta (typename , (), ns )
1689
+ return _TypedDictMeta (typename , (), ns , total = total )
1688
1690
1689
1691
_typeddict_new .__text_signature__ = ('($cls, _typename, _fields=None,'
1690
1692
' /, *, total=True, **kwargs)' )
1691
1693
1692
1694
class _TypedDictMeta (type ):
1695
+ def __init__ (cls , name , bases , ns , total = True ):
1696
+ # In Python 3.4 and 3.5 the __init__ method also needs to support the keyword arguments.
1697
+ # See https://www.python.org/dev/peps/pep-0487/#implementation-details
1698
+ super (_TypedDictMeta , cls ).__init__ (name , bases , ns )
1699
+
1693
1700
def __new__ (cls , name , bases , ns , total = True ):
1694
1701
# Create new typed dict class object.
1695
1702
# This method is called directly when TypedDict is subclassed,
0 commit comments