-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Bug Report
it seems that mypy doesn't "match" a NotRequired field with a normal one when duck typing 2 different typed dict:
Let's say that I have a function foo that expect a Small TypedDict as parameter
class Small(TypedDict):
a: NotRequired[str]
def foo(small: Small) -> None: ...In this Small TypedDict the field a is marked as NotRequired.
Elsewere I have another Big TypedDict with 2 fields a, and b, both required.
class Big(TypedDict):
a: str
b: strbut if I try to pass a Big dict instance to my foo function, mypy mark it as an error:
main.py:21: error: Argument 1 to "foo" has incompatible type "Big"; expected "Small" [arg-type]
If I change the type of Big.a to a NotRequired[str], mypy is happy, however mypy should allow the original definition, as a "normal" field should be treated as a stricter, "smaller" version of a not required one