mypy
mypy copied to clipboard
possibly-undefined not catching unbound variable in try/finally block
Bug Report
The possibly-undefined check is not catching a possibly unbound variable when it's used within a finally block
To Reproduce
The following code raises NameError: name 'val' is not defined at runtime but passes he possibly-undefined check:
def foo() -> int:
raise Exception()
try:
val = foo()
except ValueError:
val = 1
finally:
print(val)
Your Environment
- Mypy version used:
1.10.0 - Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files):
[tool.mypy]
enable_error_code = ["possibly-undefined", "redundant-expr", "truthy-bool"]
incremental = false
strict = true
warn_unreachable = true
- Python version used:
3.9.17