Skip to content

False negative: "Name not defined" error should be reported when variable is declared with a type annotation but not assigned to before use #11342

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

Closed
waleedmebane opened this issue Oct 15, 2021 · 1 comment
Labels
bug mypy got something wrong topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@waleedmebane
Copy link

Bug Report

x: int
print(x)

Mypy does not report an error for the code above or for this code:

print(x)
x = 0

But reports:
error: Name "x" is not defined

for:

print(x)

At runtime Python reports:
NameError: name 'x' is not defined

in all three cases.

Expected Behavior

Mypy should report Name "x" is not defined in all three cases.

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: Python 3.9.5 (default, Jul 19 2021, 01:21:38)
  • Operating system and version: Ubuntu 16.04
@waleedmebane waleedmebane added the bug mypy got something wrong label Oct 15, 2021
@waleedmebane waleedmebane changed the title "Name not defined" error should be reported when variable is declared with a type annotation but not assigned to before use False negative: "Name not defined" error should be reported when variable is declared with a type annotation but not assigned to before use Oct 15, 2021
@AlexWaygood AlexWaygood added the topic-runtime-semantics mypy doesn't model runtime semantics correctly label Apr 7, 2022
@AlexWaygood
Copy link
Member

Duplicate of #686

@AlexWaygood AlexWaygood marked this as a duplicate of #686 Apr 7, 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 topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

No branches or pull requests

2 participants