Skip to content

mypy ignores possible changes of global variables outside current function #11051

Closed as duplicate of#11969
@lilydjwg

Description

@lilydjwg

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions