Expected TypedDict key to be string literal for Union of TypedDict and dict
#2292
-
|
I'm getting from typing import TypedDict
class Foo(TypedDict):
some: str
name: str
type Bar = dict[int, float]
type Baz = Foo | Bar
baz: Baz = {"some": "foo", "name": "x"} # OK
bar: Bar = {1: 5.2, 2: 7.4} # OK
baz2: Baz = {1: 5.2} # error: Expected TypedDict key to be string literal [misc]I would expect It seems mypy does try to resolve to the baz3: Baz = {"1": 5.2} # error: Dict entry 0 has incompatible type "str": "float"; expected "int": "float" [dict-item] |
Beta Was this translation helpful? Give feedback.
Answered by
JelleZijlstra
May 19, 2026
Replies: 1 comment 4 replies
-
|
Yes, that seems like a bug in mypy. Zuban and ty have the same bug. |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
AllexVeldman
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, that seems like a bug in mypy. Zuban and ty have the same bug.