-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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] removed dunder methods in Python 3 (PLW3201) #13194
[pylint] removed dunder methods in Python 3 (PLW3201) #13194
Conversation
Add message for when the dunder method name is no longer valid in Python 3.
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLW3201 | 230 | 115 | 115 | 0 | 0 |
|
crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs
Outdated
Show resolved
Hide resolved
Thanks, this is looking great |
Shocked this isn't already covered by a pyupgrade rule |
match kind { | ||
Kind::Misspelled => format!("Bad or misspelled dunder method name `{name}`"), | ||
Kind::RemovedInPython3 => { | ||
format!("Python 2 or older only dunder method name `{name}`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlexWaygood any suggestion on how to improve the wording here? It's kind of hard to read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think removing the 'only' makes it read a bit smoother, but it might change the meaning slightly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this?
format!("Python 2 or older only dunder method name `{name}`") | |
format!("Dunder method `{name}` has no special meaning in Python 3") |
Though actually, that's a pretty good description of what the problem is in both cases. I wonder if we need to distinguish between misspelled dunder methods and those that were removed in Python 3 at all, or if we could just improve the docs (like this PR already does) and use a better error message here that applies to both cases? In both cases -- whether you've misspelled a dunder or you're using one that had its special semantics removed in Python 3 -- it's not going to cause any kind of exception to define the dunder method. It's just probably not going to do what you want, because it doesn't have any special semantics attached to it anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Way clearer!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MichaReiser What do you think about a single message for both cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit dissatisfying after all the hard work you put into this but I do like the suggested message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem, I also agree 😄
crates/ruff_linter/resources/test/fixtures/pylint/bad_dunder_method_name.py
Outdated
Show resolved
Hide resolved
...s/pylint/snapshots/ruff_linter__rules__pylint__tests__PLW3201_bad_dunder_method_name.py.snap
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot!
Summary
Add message for deprecated dunder methods not supported in Python 3
This PR addresses issue #12883 by adding custom messages in
PLW3201
for dunder methods that were deprecated in Python 2 and are no longer valid in Python 3. The message is displayed for the dunder methods listed in #12607 and additional methods that are no longer part of Python 3 documentation:__iop__
__rop__
__op__
fixes #12883
Test Plan
New snapshot added and
cargo test