Summary
from typing import TypedDict
class Foo:
asdf: list[int | str]
class Bar(TypedDict):
asdf: list[int | str]
def fn(foo: Foo, bar: Bar):
bar["asdf"] = list([1]) # error: Invalid assignment to key "asdf" with declared type `list[int | str]` on TypedDict `Bar`: value of type `list[int]` (invalid-assignment)
foo.asdf = list([1]) # no error, correctly inferred as list[int | str]
https://play.ty.dev/2e780e02-941e-405b-b65e-6c61a81857cf
this bug seems to have been introduced in v0.0.21
Version
0.0.21