mypy icon indicating copy to clipboard operation
mypy copied to clipboard

possibly-undefined not catching unbound variable in try/finally block

Open amh4r opened this issue 1 year ago • 0 comments

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

amh4r avatar Jun 15 '24 13:06 amh4r