unrecognized-platform-check (PYI007)
Added in v0.0.246 · Related issues · View source
Derived from the flake8-pyi linter.
What it does
Check for unrecognized sys.platform checks. Platform checks should be
simple string comparisons.
Note: this rule is only enabled in .pyi stub files.
Why is this bad?
Some sys.platform checks are too complex for type checkers to
understand, and thus result in incorrect inferences by these tools.
sys.platform checks should be simple string comparisons, like
if sys.platform == "linux".
Example
import sys
if sys.platform == "xunil"[::-1]:
# Linux specific definitions
...
else:
# Posix specific definitions
...
Instead, use a simple string comparison, such as == or !=:
import sys
if sys.platform == "linux":
# Linux specific definitions
...
else:
# Posix specific definitions
...