Skip to content

mypy does not recognize sys.platform with ternary operatorΒ #13003

Open
@amatyukhin0

Description

@amatyukhin0

Bug Report

mypy can recognize sys.platform in if cond: ... / else: ... conditions but fails to do it if ternary operator (a if cond else b) is used.

To Reproduce

Consider this piece of code, assuming we are on Linux:

import signal
import sys

signal_type = signal.SIGBREAK if sys.platform == 'win32' else signal.SIGTERM

Expected Behavior

mypy should not raise any error.

Actual Behavior

mypy fails with:

main.py:4: error: Module has no attribute "SIGBREAK"
Found 1 error in 1 file (checked 1 source file)

Environment

  • Mypy version used: 0.961
  • Python version used: 3.10
  • Operating system: Linux

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions