Skip to content

Platform check is not remembered after return #14940

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

Open
bersbersbers opened this issue Mar 23, 2023 · 0 comments · May be fixed by #18539
Open

Platform check is not remembered after return #14940

bersbersbers opened this issue Mar 23, 2023 · 0 comments · May be fixed by #18539
Labels
feature topic-type-narrowing Conditional type narrowing / binder

Comments

@bersbersbers
Copy link

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
@bersbersbers bersbersbers added the bug mypy got something wrong label Mar 23, 2023
@ichard26 ichard26 added feature topic-type-narrowing Conditional type narrowing / binder and removed bug mypy got something wrong labels Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-type-narrowing Conditional type narrowing / binder
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants