mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 13:18:18 +00:00
![]() ## Summary Part of #18972 Both in one PR since they are in the same file No playground links since the playground does not support rules that only apply to PYI files PYI007 --- This PR makes [unrecognized-platform-check (PYI007)](https://docs.astral.sh/ruff/rules/unrecognized-platform-check/#unrecognized-platform-check-pyi007)'s example error out-of-the-box Old example: ``` PS ~\Desktop\New_folder\ruff>echo @" ``` ```py if sys.platform.startswith("linux"): # Linux specific definitions ... else: # Posix specific definitions ... ``` ``` "@ | uvx ruff check --isolated --preview --select PYI007 --stdin-filename "test.pyi" - ``` ``` All checks passed! ``` New example: ``` PS ~\Desktop\New_folder\ruff>echo @" ``` ```py import sys if sys.platform is "linux": # Linux specific definitions ... else: # Posix specific definitions ... ``` ``` "@ | uvx ruff check --isolated --preview --select PYI007 --stdin-filename "test.pyi" - ``` ```snap test.pyi:3:4: PYI007 Unrecognized `sys.platform` check | 1 | import sys 2 | 3 | if sys.platform is "linux": | ^^^^^^^^^^^^^^^^^^^^^^^ PYI007 4 | # Linux specific definitions 5 | ... | Found 1 error. ``` Imports were also added to the "use instead" section > [!NOTE] > `PYI007` is really hard to trigger, it's only specifically in the case of a comparison where the operator is not `!=` or `==`. The original example raises [complex-if-statement-in-stub (PYI002)](https://docs.astral.sh/ruff/rules/complex-if-statement-in-stub/#complex-if-statement-in-stub-pyi002) with or without the `import sys` PYI008 --- This PR makes [unrecognized-platform-name (PYI008)](https://docs.astral.sh/ruff/rules/unrecognized-platform-name/#unrecognized-platform-name-pyi008)'s example error out-of-the-box Old example: ``` PS ~\Desktop\New_folder\ruff>echo @" ``` ```py if sys.platform == "linus": ... ``` ``` "@ | uvx ruff check --isolated --preview --select PYI008 --stdin-filename "test.pyi" - ``` ``` All checks passed! ``` New example: ``` PS ~\Desktop\New_folder\ruff>echo @" ``` ```py import sys if sys.platform == "linus": ... ``` ``` "@ | uvx ruff check --isolated --preview --select PYI008 --stdin-filename "test.pyi" - ``` ```snap test.pyi:3:20: PYI008 Unrecognized platform `linus` | 1 | import sys 2 | 3 | if sys.platform == "linus": ... | ^^^^^^^ PYI008 | Found 1 error. ``` Imports were also added to the "use instead" section > [!NOTE] > The original example raises `PYI002` instead ## Test Plan <!-- How was it tested? --> N/A, no functionality/tests affected --------- Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> |
||
---|---|---|
.. | ||
ruff | ||
ruff_annotate_snippets | ||
ruff_benchmark | ||
ruff_cache | ||
ruff_db | ||
ruff_dev | ||
ruff_diagnostics | ||
ruff_formatter | ||
ruff_graph | ||
ruff_index | ||
ruff_linter | ||
ruff_macros | ||
ruff_notebook | ||
ruff_options_metadata | ||
ruff_python_ast | ||
ruff_python_ast_integration_tests | ||
ruff_python_codegen | ||
ruff_python_formatter | ||
ruff_python_index | ||
ruff_python_literal | ||
ruff_python_parser | ||
ruff_python_semantic | ||
ruff_python_stdlib | ||
ruff_python_trivia | ||
ruff_python_trivia_integration_tests | ||
ruff_server | ||
ruff_source_file | ||
ruff_text_size | ||
ruff_wasm | ||
ruff_workspace | ||
ty | ||
ty_ide | ||
ty_project | ||
ty_python_semantic | ||
ty_server | ||
ty_test | ||
ty_vendored | ||
ty_wasm |