-
Notifications
You must be signed in to change notification settings - Fork 274
Description
The spec says:
First, any TypedDict type is assignable to
Mapping[str, object].Second, a TypedDict type
Bis assignable to a TypedDictAif and only if both of these conditions are satisfied:
For each key in
A,Bhas the corresponding key and the corresponding value type inBis consistent with the value type inA.For each required key in
B, the corresponding key is required inA. For each non-required key inB, the corresponding key is not required inA.
However, the following seems to be accepted by type checkers:
from typing import TypedDict
class A(TypedDict):
a: int
class B(TypedDict):
a: int
b: str
def func(a: A): pass
b: B = ...
func(b) # OKHowever, following the second point, any required key in B should be required in A. Or, b is required in B but not required (because not defined) in A.
@JelleZijlstra suggested that the second bullet point should be updated to:
For each required key in
A, the corresponding key is required inB. For each non-required key inA, the corresponding key is not required inB.
Should we also say something about extra keys are allowed to be present in B?