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
def test_func() -> int:
y: bool = False
if y:
x = 5
return x # No error
When a variable is defined behind a conditional with type bool, then mypy doesn't flag that the variable might not exist outside of the condition. I noticed that mypy can tell that the variable is False, then it will at least say "cannot determine type of x", but not when the variable is just a bool.
This will very often be a runtime error, so I would expect mypy to throw here. Is this behavior intended?
The text was updated successfully, but these errors were encountered:
This looks like a bug to me:
When a variable is defined behind a conditional with type
bool
, then mypy doesn't flag that the variable might not exist outside of the condition. I noticed that mypy can tell that the variable isFalse
, then it will at least say "cannot determine type of x", but not when the variable is just a bool.This will very often be a runtime error, so I would expect mypy to throw here. Is this behavior intended?
The text was updated successfully, but these errors were encountered: