Skip to content

Unreachability depends on statement ordering #18901

Open
coderabbit-test/mypy
#1
@A5rocks

Description

@A5rocks

Bug Report

X and sys.platform == "win32" does not mark the block as unreachable, but sys.platform == "win32" and X does. This probably has been reported before but I'm not sure how to phrase this let alone search issues.

To Reproduce

import sys

X = True

if X and sys.platform == "win32":
    reveal_type(False)  # N: Revealed type is "Literal[False]?"

Expected Behavior

I expect the branch to be unreachable, so the reveal_type should not show anything

Your Environment

Reproduced in mypy play.

  • Mypy version used: v1.15
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-reachabilityDetecting unreachable code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions