Skip to content

sys.platform != "foo" defeats platform-specific path #18873

Closed as duplicate of#10773
@Jacobfaib

Description

@Jacobfaib
import sys


def foo() -> None:
    if sys.platform != "darwin":
        print("not darwin")
        return

    print("darwin")
$ mypy --platform linux plat.py
plat.py: note: In function "foo":
plat.py:9:5: error: Statement is unreachable  [unreachable]
        print("darwin")
        ^~~~~~~~~~~~~~~
Found 1 error in 1 file (checked 1 source file)

mypy claims to understand sys.platform checks, yet is defeated by !=.

I would expect mypy not to warn about unreachable code here:

  1. I am not assigning sys.platform to an intermediate
  2. I am checking against a literal value (which in the documentation mypy also claims to understand).

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