Visitar URL original
[pylint] Implement pointless-string-statement (PLW0105) by oehlschl · Pull Request #27253 · astral-sh/ruff · GitHub
Skip to content

[pylint] Implement pointless-string-statement (PLW0105) - #27253

Closed
oehlschl wants to merge 1 commit into
astral-sh:mainfrom
oehlschl:pointless-string-statement
Closed

oehlschl wants to merge 1 commit into
astral-sh:mainfrom
oehlschl:pointless-string-statement

Conversation

@oehlschl

Copy link
Copy Markdown

Summary

  • I noticed that ruff had not yet ported over pylint's pointless-string-statement (W0105) rule, after finding some offenses in our own codebase and figuring there would be enough source material to make the fix upstream
  • accordingly, this checks off one parity box from Implement Pylint #970, by implementing pointless-string-statement as PLW0105
  • I based the implementation off of pylint (rather than PEP 257) for parity, and it's worth noting that they differ in one spot: PEP 257 also recognizes "additional docstrings" (a string right after the real docstring), but they are flagged by pylint. No strong opinion here but I kept the pylint logic for parity and documented the difference in code; happy to change if desired.

Changes

  • dispatched from analyze/suite.rs (same entry point as PYI021) because the exemptions need the previous sibling statement
  • didn't use the existing ExpectedDocstringKind::Attribute since it was narrower than pylint's exemption (no __init__, no TypeAlias, single-Name targets only)
  • ended up having to touch flake8-bugbear in order to generalize at_last_top_level_expression_in_cell for the sake of notebook handling: strings that are a cell's last top-level expression are the cell's displayed output and are exempted, matching B015/B018. The rule runs at suite-analysis time, where current_statement() isn't populated, so the helper now takes the statement's end offset as a parameter instead. Alternatives to generalizing in-place are duplicating some logic into the pylint rule, or relocating the helper. (Note that B015/B018 behavior is unchanged and their tests were not modified.)
  • no remediation path here because the fix depends on the original intent

Test Plan

  • ported over pylint's test coverage for the rule, and added new notebook tests
  • compared to a run of pylint against a large private codebase; matched line-for-line on 93 offenses

Assisted by AI

Co-Authored-By: Claude <noreply@anthropic.com>
@oehlschl
oehlschl marked this pull request as ready for review July 28, 2026 19:20
@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre July 28, 2026 19:20
@oehlschl oehlschl mentioned this pull request Jul 28, 2026
@ntBre

ntBre commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Thanks for looking into this! It sounds like this was previously explored/tracked as an expansion to useless-expression (B018), which makes some sense to me. There's even an existing draft PR doing that: #11302. I would probably lean toward reviving that PR and expanding the scope of B018 in preview over introducing a new rule with a similar but much narrower scope.

@oehlschl

Copy link
Copy Markdown
Author

Thanks for pointing me at that; I just saw that the rule was unclaimed in the pylint thread, but I agree with the sentiment about near-duplicate rules. I'll take a look at what it would need to see the B018 version to completion.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants