-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-572PEP 572 (walrus operator)PEP 572 (walrus operator)
Description
Bug Report
mypy sometimes fails to report errors in assignment expressions inside a tuple.
To Reproduce
def condition() -> bool: return False
def fn() -> tuple[int, int]:
i: int | None = 0 if condition() else None
return (i, (i := i + 1))
print(fn())Expected Behavior
Something like
lib.py:5: error: Incompatible return value type (got "tuple[int | None, int]", expected "tuple[int, int]") [return-value]
lib.py:5: error: Unsupported operand types for + ("None" and "int") [operator]
lib.py:5: note: Left operand is of type "int | None"
Actual Behavior
Success: no issues found in 1 source file
Your Environment
- Mypy version used: 1.19.1 and master
- Mypy command-line flags: n/a
- Mypy configuration options from
mypy.ini(and other config files): n/a - Python version used: 3.14.2
The weird thing is that if I change assignment target to a different variable like (i, (j := i + 1)) mypy reports the two errors above.
Possibly related to mypyc/mypyc#1179
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-572PEP 572 (walrus operator)PEP 572 (walrus operator)