-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-join-v-unionUsing join vs. using unionsUsing join vs. using unions
Description
https://mypy-play.net/?mypy=1.17.0&python=3.12&gist=25e4031ca17d70626baee7a468ac4d9f
def ternary_list[T, S](x: list[T], y: list[S]) -> None:
a = x if "" else y
reveal_type(a) # list[T] | list[S] ✅
def ternary_list2() -> None:
a = list[int]() if "" else list[str]()
reveal_type(a) # list[int] | list[str] ✅
def ternary_list_literal() -> None:
a = [1] if "" else ["a"] # E: List item 0 has incompatible type "str"
reveal_type(a) # list[int] ???
I would have expected list[int] | list[str]
in the literal case as well.
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-join-v-unionUsing join vs. using unionsUsing join vs. using unions