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 ignores possible changes of global variables outside current function #11051

Open
lilydjwg opened this issue Sep 3, 2021 · 1 comment
Open
Labels
bug mypy got something wrong

Comments

@lilydjwg
Copy link

lilydjwg commented Sep 3, 2021

Bug Report

See code.

To Reproduce

from typing import Optional

class Global:
  attr: Optional[int] = None

G = Global()

def f() -> None:
  G.attr = 1

def t() -> None:
  G.attr = None
  f()
  assert G.attr is not None
  reveal_type(G)
  1. Write the above code
  2. Run mypy on it

Expected Behavior

Mypy shows the type of G at the last line (and G.attr is of type int).

Actual Behavior

Mypy completely skips the lines below assert.

Success: no issues found in 1 source file

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: no other args than the file
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9.6
  • Operating system and version: Arch Linux current
@lilydjwg lilydjwg added the bug mypy got something wrong label Sep 3, 2021
@KotlinIsland
Copy link
Contributor

KotlinIsland commented Feb 7, 2022

#11649
#11969

This issue a well known limitation.

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