Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy not detecting referenced before assignment #13510

Closed
stephan-nordnes-eriksen opened this issue Aug 25, 2022 · 1 comment
Closed

Mypy not detecting referenced before assignment #13510

stephan-nordnes-eriksen opened this issue Aug 25, 2022 · 1 comment
Labels
bug mypy got something wrong

Comments

@stephan-nordnes-eriksen
Copy link

stephan-nordnes-eriksen commented Aug 25, 2022

Bug Report

Not catching reference before assignment.

To Reproduce

The following code results in UnboundLocalError: local variable 'result' referenced before assignment if run, but mypy does not report an issue.

def foo(input: bool):
    if input:
        result = "value"
        print('result set')
    else:
        print('result is not assigned')

    return result

a = foo(False)

Expected Behavior

I would expect mypy to complain about result being referenced before assignment.

Actual Behavior

Success: no issues found in 1 source file

Your Environment

  • Mypy version used: 0.980+dev.61a9b92297e1363b5bd99855df51e9a84be8da69 (current master)
  • Mypy command-line flags: (none)
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10.5 and 3.9.7 (both with pyenv)
  • Operating system and version: Ubuntu 20.04.4 LTS

Notes
This is my firt bug report to mypy, so I'm sorry if this issue is already reported (I was not able to find it), or if this is out of scope for mypy. I do also realize that this is halting-problem-esque, but I believe this category of problem should be possible to resolve with static analysis.

@stephan-nordnes-eriksen stephan-nordnes-eriksen added the bug mypy got something wrong label Aug 25, 2022
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Aug 25, 2022

Duplicate of #686 / #4019 / #2400

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants