-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed as duplicate of#17383
Labels
bugmypy got something wrongmypy got something wrongtopic-join-v-unionUsing join vs. using unionsUsing join vs. using unions
Description
Bug Report
mypy can not handle T | None when T is also an union.
To Reproduce
Run mypy on the following code.
def unwrap[T](value: T | None) -> T:
assert value is not None
return value
def f(value: int | str) -> None:
pass
def main() -> None:
value: int | str | None = 42
f(unwrap(value))https://mypy-play.net/?mypy=latest&python=3.12&gist=7c62868a7c9a0afc4853487fdd605f4b
Expected Behavior
mypy does not show any errors.
unwrap(value) converts int | str | None to int | str.
Actual Behavior
main.py:12: error: Argument 1 to "f" has incompatible type "object"; expected "int | str" [arg-type]
Found 1 error in 1 file (checked 1 source file)
mypy handles unwrap(value) as object and raises an error.
Your Environment
- Mypy version used: 1.18.2
- Mypy command-line flags: default of playground
- Mypy configuration options from
mypy.ini(and other config files): default of playground - Python version used: 3.12
toslunar, himkt, ktns, keisuke-nakata, not522 and 2 more
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-join-v-unionUsing join vs. using unionsUsing join vs. using unions