TypeGuard does not narrow when assignment expression #17088
Labels
bug
mypy got something wrong
topic-pep-572
PEP 572 (walrus operator)
topic-typeguard
TypeGuard / PEP 647
Bug Report
In the example below,
is_str
is a type guard, but when used mypy fails to narrow the type. I'm pretty sure this happens because of the assignment expression.To Reproduce
https://mypy-play.net/?mypy=latest&python=3.12&gist=42da00a72ace0a51a5d2335721877591
Expected Behavior
No mypy errors.
Actual Behavior
main.py:14: error: Unsupported operand types for + ("int" and "str") [operator]
main.py:14: note: Left operand is of type "str | int"
Found 1 error in 1 file (checked 1 source file)
Your Environment
mypy.ini
(and other config files): nonThe text was updated successfully, but these errors were encountered: