mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-04 01:36:46 +00:00
Add two [flake8-pyi](https://github.com/PyCQA/flake8-pyi) rules (Y007, Y008). ref: #848 The specifications are described in [PEP 484 - Version and platform checking](https://peps.python.org/pep-0484/#version-and-platform-checking) The original implementation in flake8-pyi is shown below. - Implemention:66f28a4407/pyi.py (L1429-L1443)- Tests:66f28a4407/tests/sysplatform.pyi
880 B
880 B
unrecognized-platform-check (PYI007)
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 false positives. sys.platform checks
should be simple string comparisons, like sys.platform == "linux".
Example
if sys.platform.startswith("linux"):
# Linux specific definitions
else:
# Posix specific definitions
Instead, use a simple string comparison, such as == or !=:
if sys.platform == "linux":
# Linux specific definitions
else:
# Posix specific definitions