from typing_extensions import TypedDict
from typing import Optional
class A(TypedDict):
x: Optional[int]
class B(TypedDict):
x: int
def f(a: A) -> None:
a['x'] = None
b: B = {'x': 0}
f(b) # Type check error: 'B' not compatible with 'A'
b['x'] + 1 # Runtime error: None + 1
Agreed, pytype should flag this. We (the pytype devs) discussed this briefly, and we probably want to match mutable and immutable container types differently.
Example Code
Expected Behavior
error: incompatible type argument in function f
Actual Behavior
Example works as expected in mypy.