Skip to content

Commit

Permalink
[pylint] removed dunder methods in Python 3 (PLW3201) (#13194)
Browse files Browse the repository at this point in the history
Co-authored-by: Micha Reiser <micha@reiser.io>
  • Loading branch information
iamlucasvieira and MichaReiser authored Sep 4, 2024
1 parent e37bde4 commit 9d1bd7a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def __prepare__():
def __mro_entries__(self, bases):
pass

# Removed with Python 3
def __unicode__(self):
pass

def __foo_bar__(): # this is not checked by the [bad-dunder-name] rule
...
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::checkers::ast::Checker;
use crate::rules::pylint::helpers::is_known_dunder_method;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
bad_dunder_method_name.py:5:9: PLW3201 Bad or misspelled dunder method name `_init_`
bad_dunder_method_name.py:5:9: PLW3201 Dunder method `_init_` has no special meaning in Python 3
|
4 | class Apples:
5 | def _init_(self): # [bad-dunder-name]
| ^^^^^^ PLW3201
6 | pass
|

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

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

bad_dunder_method_name.py:15:9: PLW3201 Bad or misspelled dunder method name `_init_`
bad_dunder_method_name.py:15:9: PLW3201 Dunder method `_init_` has no special meaning in Python 3
|
13 | pass
14 |
Expand All @@ -38,7 +38,7 @@ bad_dunder_method_name.py:15:9: PLW3201 Bad or misspelled dunder method name `_i
17 | pass
|

bad_dunder_method_name.py:19:9: PLW3201 Bad or misspelled dunder method name `___neg__`
bad_dunder_method_name.py:19:9: PLW3201 Dunder method `___neg__` has no special meaning in Python 3
|
17 | pass
18 |
Expand All @@ -48,7 +48,7 @@ bad_dunder_method_name.py:19:9: PLW3201 Bad or misspelled dunder method name `__
21 | pass
|

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


bad_dunder_method_name.py:98:9: PLW3201 Dunder method `__unicode__` has no special meaning in Python 3
|
97 | # Removed with Python 3
98 | def __unicode__(self):
| ^^^^^^^^^^^ PLW3201
99 | pass
|

0 comments on commit 9d1bd7a

Please # to comment.