Skip to content

Commit

Permalink
Avoid flagging bad-dunder-method-name for _ (#8015)
Browse files Browse the repository at this point in the history
This is almost certainly _not_ an accidentally mistyped dunder method.
Closes #8005.
  • Loading branch information
charliermarsh authored Oct 17, 2023
1 parent 8a52992 commit d942a77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def __html__(self):
def _missing_(cls, value):
pass

# Allow anonymous functions.
def _(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 @@ -54,7 +54,7 @@ pub(crate) fn bad_dunder_method_name(checker: &mut Checker, class_body: &[Stmt])
.iter()
.filter_map(ruff_python_ast::Stmt::as_function_def_stmt)
.filter(|method| {
if is_known_dunder_method(&method.name) {
if is_known_dunder_method(&method.name) || matches!(method.name.as_str(), "_") {
return false;
}
method.name.starts_with('_') && method.name.ends_with('_')
Expand Down

0 comments on commit d942a77

Please sign in to comment.