class Foo(TypedDict, extra=True):
foo = Foo(a=1, b="bar")
foo["c"] = "some other value" # no mypy/typeshed error
foo["a"] = "mismatch type" # mypy/typeshed error
Sometimes we have dict with partially typed and we want to use types for known part with all typechecker power, but without false positive warnings for extra part.
Seems like a straightforward, helpful, non-breaking change to me.
It’s been proposed a few times before to provide a spelling for a TypedDict that defines the expected value type for any unknown keys. However no individual has yet had enough motivation to shepherd that feature to a full PEP, as far as I can remember.
From the thread referenced above, Eric Traut put forward a fairly complete proposal here which suggests a syntax like:
__extra__: str | None
In the above syntax @bomzheg 's original example would look like: