Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pylint] Fix missing parens in unsafe fix for unnecessary-dunder-call (PLC2801) #15762

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mishamsk
Copy link
Contributor

Summary

This fixes #15745

Also, I haven't found a trait/helper to get expression precedence. Even though at least 3 rules check precedence when generating fixes. Generally speaking, unless/until fixes are done via AST generation - many (all?) fixes involving expression rewrites would need to consult precedence to handle parens. Unless I am mistaken.

Thus, I've implemented an enum and a trait. But I didn't dare doing that in semantic/AST crates, although I believe it would be helpful to move them there.

@AlexWaygood @dylwil3 you'll know the codebase better, let me know if you think it should be elevated to some core base crate. If you do, I am happy to implement this, but will need your guidance on where you'd like it to reside.

Test Plan

  • Updated test case with 2 examples from the issue + a couple of mine, including one that would generate invalid python program before this fix
  • cargo nextest run (check updated snapshot)

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dylwil3 dylwil3 self-assigned this Jan 29, 2025
@dylwil3 dylwil3 changed the title [pylint] Fix missing parens in unsafe fix (PLC2801) [pylint] Fix missing parens in unsafe fix for unnecessary-dunder-call (PLC2801) Jan 30, 2025
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.

PLC2801 fix needs parentheses before subscript or attribute access
2 participants