Skip to content

[flake8-pyi] Mention stubs in the diagnostic message (PYI002) - #28542

Merged
ntBre merged 1 commit into
astral-sh:mainfrom
devtechedge:pyi002-stub-file-message
Sep 17, 2026
Merged

ntBre merged 1 commit into
astral-sh:mainfrom
devtechedge:pyi002-stub-file-message

Conversation

@devtechedge

Copy link
Copy Markdown
Contributor

Fixes #27324

The PYI002 diagnostic read as a statement about the flagged test itself, which is confusing when the condition does not mention sys.platform or sys.version_info at all (the case in the issue). The rule's expectation is that if tests in stub files are simple comparisons, so the message now names that context:

PYI002 `if` test in a stub file must be a simple comparison against `sys.platform` or `sys.version_info`

This is a message-only change; rule behavior is unchanged. The Y002 fixtures and snapshots are untouched since that rule carries its own message, and the PYI002.pyi.snap output is updated to match.

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre September 11, 2026 21:58
devtechedge added a commit to devtechedge/oss-contributions that referenced this pull request Sep 11, 2026
devtechedge added a commit to devtechedge/oss-contributions that referenced this pull request Sep 12, 2026
@ntBre ntBre added the diagnostics Related to reporting of diagnostics. label Sep 17, 2026
@ntBre ntBre changed the title Improve PYI002 diagnostic message to name the stub-file context [flake8-pyi] Mention stubs in the diagnostic message (PYI002) Sep 17, 2026

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks

@ntBre
ntBre enabled auto-merge (squash) September 17, 2026 14:25
@ntBre ntBre closed this Sep 17, 2026
auto-merge was automatically disabled September 17, 2026 14:30

Pull request was closed

@ntBre ntBre reopened this Sep 17, 2026
@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre September 17, 2026 14:31
@ntBre
ntBre enabled auto-merge (squash) September 17, 2026 14:31
@astral-sh-bot

astral-sh-bot Bot commented Sep 17, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+4 -4 violations, +0 -0 fixes in 1 projects; 58 projects unchanged)

bokeh/bokeh (+4 -4 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --no-preview --select ALL

+ src/bokeh/core/property/visual.pyi:19:4: PYI002 `if` test in a stub file must be a simple comparison against `sys.platform` or `sys.version_info`
- src/bokeh/core/property/visual.pyi:19:4: PYI002 `if` test must be a simple comparison against `sys.platform` or `sys.version_info`
+ src/bokeh/models/plots.pyi:52:4: PYI002 `if` test in a stub file must be a simple comparison against `sys.platform` or `sys.version_info`
- src/bokeh/models/plots.pyi:52:4: PYI002 `if` test must be a simple comparison against `sys.platform` or `sys.version_info`
+ src/bokeh/models/sources.pyi:22:4: PYI002 `if` test in a stub file must be a simple comparison against `sys.platform` or `sys.version_info`
- src/bokeh/models/sources.pyi:22:4: PYI002 `if` test must be a simple comparison against `sys.platform` or `sys.version_info`
+ src/bokeh/plotting/_figure.pyi:25:4: PYI002 `if` test in a stub file must be a simple comparison against `sys.platform` or `sys.version_info`
- src/bokeh/plotting/_figure.pyi:25:4: PYI002 `if` test must be a simple comparison against `sys.platform` or `sys.version_info`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PYI002 8 4 4 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+4 -4 violations, +0 -0 fixes in 1 projects; 58 projects unchanged)

bokeh/bokeh (+4 -4 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview --select ALL

+ src/bokeh/core/property/visual.pyi:19:4: complex-if-statement-in-stub `if` test in a stub file must be a simple comparison against `sys.platform` or `sys.version_info`
- src/bokeh/core/property/visual.pyi:19:4: complex-if-statement-in-stub `if` test must be a simple comparison against `sys.platform` or `sys.version_info`
+ src/bokeh/models/plots.pyi:52:4: complex-if-statement-in-stub `if` test in a stub file must be a simple comparison against `sys.platform` or `sys.version_info`
- src/bokeh/models/plots.pyi:52:4: complex-if-statement-in-stub `if` test must be a simple comparison against `sys.platform` or `sys.version_info`
+ src/bokeh/models/sources.pyi:22:4: complex-if-statement-in-stub `if` test in a stub file must be a simple comparison against `sys.platform` or `sys.version_info`
- src/bokeh/models/sources.pyi:22:4: complex-if-statement-in-stub `if` test must be a simple comparison against `sys.platform` or `sys.version_info`
+ src/bokeh/plotting/_figure.pyi:25:4: complex-if-statement-in-stub `if` test in a stub file must be a simple comparison against `sys.platform` or `sys.version_info`
- src/bokeh/plotting/_figure.pyi:25:4: complex-if-statement-in-stub `if` test must be a simple comparison against `sys.platform` or `sys.version_info`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
complex-if-statement-in-stub 8 4 4 0 0

@ntBre
ntBre merged commit 3709494 into astral-sh:main Sep 17, 2026
96 of 98 checks passed
@devtechedge

Copy link
Copy Markdown
Contributor Author

Thanks for merging, @ntBre.

Your rename to the [flake8-pyi] scope with the rule code in parens is a convention I will mirror on future Ruff PRs.

Keeping this one message-only while Y002 carried its own wording made the review story much cleaner than bundling the two.

Appreciate the quick review cycle here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PYI002: Confusing/Unclear error message

2 participants