[pylint] removed dunder methods in Python 3 (PLW3201)#13194
[pylint] removed dunder methods in Python 3 (PLW3201)#13194MichaReiser merged 7 commits intoastral-sh:mainfrom
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.
@AlexWaygood any suggestion on how to improve the wording here? It's kind of hard to read
There was a problem hiding this comment.
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.
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.
@MichaReiser What do you think about a single message for both cases?
There was a problem hiding this comment.
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.
No problem, I also agree 😄
Summary
Add message for deprecated dunder methods not supported in Python 3
This PR addresses issue #12883 by adding custom messages in
PLW3201for 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