Skip to content

Conversation

MeGaGiGaGon
Copy link
Contributor

@MeGaGiGaGon MeGaGiGaGon commented Jul 2, 2025

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)'s example error out-of-the-box

Old example:

PS ~\Desktop\New_folder\ruff>echo @"
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 @"
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" -
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) with or without the import sys

PYI008

This PR makes unrecognized-platform-name (PYI008)'s example error out-of-the-box

Old example:

PS ~\Desktop\New_folder\ruff>echo @"
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 @"
import sys

if sys.platform == "linus": ...
"@ | uvx ruff check --isolated --preview --select PYI008 --stdin-filename "test.pyi" -
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

N/A, no functionality/tests affected

Copy link
Contributor

github-actions bot commented Jul 2, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@MichaReiser MichaReiser added the documentation Improvements or additions to documentation label Jul 7, 2025
@AlexWaygood AlexWaygood merged commit 6e77e1b into astral-sh:main Jul 7, 2025
35 checks passed
@MeGaGiGaGon MeGaGiGaGon deleted the patch-1 branch July 7, 2025 20:12
UnboundVariable pushed a commit to UnboundVariable/ruff that referenced this pull request Jul 7, 2025
…c_tokens

* 'main' of https://github.com/astral-sh/ruff: (27 commits)
  [ty] First cut at semantic token provider (astral-sh#19108)
  [`flake8-simplify`] Make example error out-of-the-box (`SIM116`) (astral-sh#19111)
  [`flake8-use-pathlib`] Make example error out-of-the-box (`PTH210`) (astral-sh#19189)
  [`flake8-use-pathlib`] Add autofixes for `PTH203`, `PTH204`, `PTH205` (astral-sh#18922)
  [`flake8-type-checking`] Fix syntax error introduced by fix (`TC008`) (astral-sh#19150)
  [`flake8-pyi`] Make example error out-of-the-box (`PYI007`, `PYI008`) (astral-sh#19103)
  Update Rust crate indicatif to 0.18.0 (astral-sh#19165)
  [ty] Add separate CI job for memory usage stats (astral-sh#19134)
  [ty] Add documentation for server traits (astral-sh#19137)
  Rename to `SessionSnapshot`, move unwind assertion closer (astral-sh#19177)
  [`flake8-type-checking`] Make example error out-of-the-box (`TC001`) (astral-sh#19151)
  [ty] Bare `ClassVar` annotations (astral-sh#15768)
  [ty] Re-enable multithreaded pydantic benchmark (astral-sh#19176)
  [ty] Implement equivalence for protocols with method members (astral-sh#18659)
  [ty] Use RHS inferred type for bare `Final` symbols (astral-sh#19142)
  [ty] Support declaration-only attributes (astral-sh#19048)
  [ty] Sync vendored typeshed stubs (astral-sh#19174)
  Update dependency pyodide to ^0.28.0 (astral-sh#19164)
  Update NPM Development dependencies (astral-sh#19170)
  Update taiki-e/install-action action to v2.56.7 (astral-sh#19169)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants