You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypedDict is really useful for expressing data with a consistent shape, but where not all fields are present.
I feel it can be improved by adding a "strict" mode for accessing items. This way, mypy can enforce that the proper checks are made.
An example to illustrate:
frommypy_extensionsimportTypedDictclassFooBase(TypedDict):
x: int# a required fieldclassFoo(FooBase, total=False):
y: int# an optional fieldf=Foo(x=5)
# current situationf['x'] # okf['y'] # okf.get('y', 0) # ok# "strict" situationf['x'] # ok (item is always present)f['y'] # FAILf.get('y', 0) # ok (explicit fallback is needed)
I understand that not everyone wants this behavior, so perhaps it would be useful as a strictness flag?
The text was updated successfully, but these errors were encountered:
TypedDict
is really useful for expressing data with a consistent shape, but where not all fields are present.I feel it can be improved by adding a "strict" mode for accessing items. This way,
mypy
can enforce that the proper checks are made.An example to illustrate:
I understand that not everyone wants this behavior, so perhaps it would be useful as a strictness flag?
The text was updated successfully, but these errors were encountered: