Skip to content

Commit 134def0

Browse files
Allow sunder names from enum.Enum (#7987)
Closes #7971.
1 parent 1fabaca commit 134def0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def __attrs_init__(self):
6363
def __html__(self):
6464
pass
6565

66+
# Allow _missing_, used by enum.Enum.
67+
@classmethod
68+
def _missing_(cls, value):
69+
pass
70+
6671

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

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,5 +196,13 @@ fn is_known_dunder_method(method: &str) -> bool {
196196
| "__trunc__"
197197
| "__weakref__"
198198
| "__xor__"
199+
// Overridable sunder names from the `Enum` class.
200+
// See: https://docs.python.org/3/library/enum.html#supported-sunder-names
201+
| "_name_"
202+
| "_value_"
203+
| "_missing_"
204+
| "_ignore_"
205+
| "_order_"
206+
| "_generate_next_value_"
199207
)
200208
}

0 commit comments

Comments
 (0)