TypedDictPEP 589を介してPython 3.8で受け入れられました。Pythonから__total__は、Trueデフォルトでブールフラグが設定されているように見えます。
tot = TypedDict.__total__
print(type(tot))
print(tot)
# <class 'bool'>
# True
他の投稿で述べたように、このメソッドの詳細はdocsで制限されていますが、CPythonソースコードへの@Yann Vernierのリンク__total__は、Python 3.8で導入された新しいtotalキーワードに関連していることを強く示唆しています。
# cypthon/typing.py
class _TypedDictMeta(type):
def __new__(cls, name, bases, ns, total=True):
"""Create new typed dict class object.
...
"""
...
if not hasattr(tp_dict, '__total__'):
tp_dict.__total__ = total
...
どのように機能しますか?
概要:デフォルトでは、定義済みのをインスタンス化するときにすべてのキーが必要ですTypedDict。 total=Falseこの制限を無効にし、オプションのキーを許可します。次のデモをご覧ください。
与えられた
テストディレクトリツリー:

コード
テストディレクトリ内のファイル:
# rgb_bad.py
from typing import TypedDict
class Color(TypedDict):
r: int
g: int
b: int
a: float
blue = Color(r=0, g=0, b=255) # missing "a"
# rgb_good.py
from typing import TypedDict
class Color(TypedDict, total=False):
r: int
g: int
b: int
a: float
blue = Color(r=0, g=0, b=255) # missing "a"
デモ
キーがない場合、mypyはコマンドラインで文句を言うでしょう:
> mypy code/rgb_bad.py
code\rgb_bad.py:11: error: Key 'a' missing for TypedDict "Color"
...
total=Falseオプションのキーを許可する設定:
> mypy code/rgb_good.py
Success: no issues found in 1 source file
こちらもご覧ください
typing内部の99%は文書化されておらず、文書化されている部分の文書化も不十分です。