Skip to content

Commit 9d1bd7a

Browse files
[pylint] removed dunder methods in Python 3 (PLW3201) (#13194)
Co-authored-by: Micha Reiser <[email protected]>
1 parent e37bde4 commit 9d1bd7a

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

crates/ruff_linter/resources/test/fixtures/pylint/bad_dunder_method_name.py

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def __prepare__():
9494
def __mro_entries__(self, bases):
9595
pass
9696

97+
# Removed with Python 3
98+
def __unicode__(self):
99+
pass
97100

98101
def __foo_bar__(): # this is not checked by the [bad-dunder-name] rule
99102
...

crates/ruff_linter/src/rules/pylint/rules/bad_dunder_method_name.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use crate::checkers::ast::Checker;
88
use crate::rules::pylint::helpers::is_known_dunder_method;
99

1010
/// ## What it does
11-
/// Checks for misspelled and unknown dunder names in method definitions.
11+
/// Checks for dunder methods that have no special meaning in Python 3.
1212
///
1313
/// ## Why is this bad?
14-
/// Misspelled dunder name methods may cause your code to not function
14+
/// Misspelled or no longer supported dunder name methods may cause your code to not function
1515
/// as expected.
1616
///
1717
/// Since dunder methods are associated with customizing the behavior
@@ -51,7 +51,7 @@ impl Violation for BadDunderMethodName {
5151
#[derive_message_formats]
5252
fn message(&self) -> String {
5353
let BadDunderMethodName { name } = self;
54-
format!("Bad or misspelled dunder method name `{name}`")
54+
format!("Dunder method `{name}` has no special meaning in Python 3")
5555
}
5656
}
5757

crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLW3201_bad_dunder_method_name.py.snap

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
source: crates/ruff_linter/src/rules/pylint/mod.rs
33
---
4-
bad_dunder_method_name.py:5:9: PLW3201 Bad or misspelled dunder method name `_init_`
4+
bad_dunder_method_name.py:5:9: PLW3201 Dunder method `_init_` has no special meaning in Python 3
55
|
66
4 | class Apples:
77
5 | def _init_(self): # [bad-dunder-name]
88
| ^^^^^^ PLW3201
99
6 | pass
1010
|
1111

12-
bad_dunder_method_name.py:8:9: PLW3201 Bad or misspelled dunder method name `__hello__`
12+
bad_dunder_method_name.py:8:9: PLW3201 Dunder method `__hello__` has no special meaning in Python 3
1313
|
1414
6 | pass
1515
7 |
@@ -18,7 +18,7 @@ bad_dunder_method_name.py:8:9: PLW3201 Bad or misspelled dunder method name `__h
1818
9 | print("hello")
1919
|
2020

21-
bad_dunder_method_name.py:11:9: PLW3201 Bad or misspelled dunder method name `__init_`
21+
bad_dunder_method_name.py:11:9: PLW3201 Dunder method `__init_` has no special meaning in Python 3
2222
|
2323
9 | print("hello")
2424
10 |
@@ -28,7 +28,7 @@ bad_dunder_method_name.py:11:9: PLW3201 Bad or misspelled dunder method name `__
2828
13 | pass
2929
|
3030

31-
bad_dunder_method_name.py:15:9: PLW3201 Bad or misspelled dunder method name `_init_`
31+
bad_dunder_method_name.py:15:9: PLW3201 Dunder method `_init_` has no special meaning in Python 3
3232
|
3333
13 | pass
3434
14 |
@@ -38,7 +38,7 @@ bad_dunder_method_name.py:15:9: PLW3201 Bad or misspelled dunder method name `_i
3838
17 | pass
3939
|
4040

41-
bad_dunder_method_name.py:19:9: PLW3201 Bad or misspelled dunder method name `___neg__`
41+
bad_dunder_method_name.py:19:9: PLW3201 Dunder method `___neg__` has no special meaning in Python 3
4242
|
4343
17 | pass
4444
18 |
@@ -48,7 +48,7 @@ bad_dunder_method_name.py:19:9: PLW3201 Bad or misspelled dunder method name `__
4848
21 | pass
4949
|
5050

51-
bad_dunder_method_name.py:23:9: PLW3201 Bad or misspelled dunder method name `__inv__`
51+
bad_dunder_method_name.py:23:9: PLW3201 Dunder method `__inv__` has no special meaning in Python 3
5252
|
5353
21 | pass
5454
22 |
@@ -58,4 +58,10 @@ bad_dunder_method_name.py:23:9: PLW3201 Bad or misspelled dunder method name `__
5858
25 | pass
5959
|
6060

61-
61+
bad_dunder_method_name.py:98:9: PLW3201 Dunder method `__unicode__` has no special meaning in Python 3
62+
|
63+
97 | # Removed with Python 3
64+
98 | def __unicode__(self):
65+
| ^^^^^^^^^^^ PLW3201
66+
99 | pass
67+
|

0 commit comments

Comments
 (0)