You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mypy 1.10.0 complains about the assignment in each of them:
test_mypy_dict.py:2: error: Incompatible types in assignment (expression has type "set[object]", variable has type "set[str] | set[int]") [assignment]
test_mypy_dict.py:5: error: Incompatible types in assignment (expression has type "dict[str | int, float]", variable has type "dict[str, float] | dict[int, float]") [assignment]
The set() or dict() operation applied on a variable that is either a list[str] | list[int] is always either a set[str] or set[int]. The same applies to function g using a dict. Thus the functions should not raise a mypy error.
Workarounds
I tried two workarounds:
Using a mixed type of list[str | int]. However, I get the type list[str] | list[int] by an external function, thus this is not compatible.
Bug Report
See these two example functions:
Mypy 1.10.0 complains about the assignment in each of them:
To Reproduce
Playground gist: https://mypy-play.net/?mypy=latest&python=3.12&gist=83bde5f3f11470e94b6a680158649641
Expected Behavior
The
set()
ordict()
operation applied on a variable that is either alist[str] | list[int]
is always either aset[str]
orset[int]
. The same applies to functiong
using adict
. Thus the functions should not raise a mypy error.Workarounds
I tried two workarounds:
list[str | int]
. However, I get the typelist[str] | list[int]
by an external function, thus this is not compatible.See the playground gist: https://mypy-play.net/?mypy=latest&python=3.12&gist=264490179628a0a214a2e5bd947b8ccf
The text was updated successfully, but these errors were encountered: