Skip to content

Platform check is not remembered after return #14940

Open
@bersbersbers

Description

@bersbersbers

Bug Report

A platform check that is working fine in if and else is not working after if ... return.

To Reproduce

import sys

def works() -> None:
    if sys.platform != "win32":
        return
    else:
        from winreg import REG_SZ

def fails() -> None:
    if sys.platform != "win32":
        return
    from winreg import REG_SZ

https://mypy-play.net/?mypy=latest&python=3.11&gist=eddad091a6082bd85c5c7524839726b1

Expected Behavior

No error.

Actual Behavior

main.py:12: error: Module "winreg" has no attribute "REG_SZ" [attr-defined]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Failure is on Linux
  • Mypy version used: 1.1.1
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.11.2

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions