Skip to content

Commit 1a26dea

Browse files
pylint-backport[bot]tqa236Pierre-Sassoulasmbyrnepr2
authored
[Backport maintenance/4.0.x] Add Enum dunder to the list of allowed dunder (#10725)
Add Enum dunder to the list of allowed dunder (#10722) (cherry picked from commit 0426f8b) Co-authored-by: Trinh Quoc Anh <[email protected]> Co-authored-by: Pierre Sassoulas <[email protected]> Co-authored-by: Mark Byrne <[email protected]>
1 parent fc920b6 commit 1a26dea

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add Enum dunder methods ``_generate_next_value_``, ``_missing_``, ``_numeric_repr_``, ``_add_alias_``, and ``_add_value_alias_`` to the list passed to ``--good-dunder-names``.
2+
3+
Closes #10435

pylint/constants.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -219,26 +219,31 @@ def _get_pylint_home() -> str:
219219
"__anext__": "Use anext built-in function",
220220
},
221221
}
222-
223-
EXTRA_DUNDER_METHODS = [
224-
"__new__",
225-
"__subclasses__",
226-
"__init_subclass__",
227-
"__set_name__",
228-
"__class_getitem__",
229-
"__missing__",
230-
"__exit__",
231-
"__await__",
232-
"__aexit__",
233-
"__getnewargs_ex__",
234-
"__getnewargs__",
235-
"__getstate__",
236-
"__index__",
237-
"__setstate__",
238-
"__reduce__",
239-
"__reduce_ex__",
240-
"__post_init__", # part of `dataclasses` module
241-
]
222+
EXTRA_DUNDER_METHODS: dict[tuple[int, int], list[str]] = {
223+
(0, 0): [
224+
"__new__",
225+
"__subclasses__",
226+
"__init_subclass__",
227+
"__set_name__",
228+
"__class_getitem__",
229+
"__missing__",
230+
"__exit__",
231+
"__await__",
232+
"__aexit__",
233+
"__getnewargs_ex__",
234+
"__getnewargs__",
235+
"__getstate__",
236+
"__index__",
237+
"__setstate__",
238+
"__reduce__",
239+
"__reduce_ex__",
240+
"__post_init__", # part of `dataclasses` module
241+
"_generate_next_value_",
242+
"_missing_",
243+
"_numeric_repr_",
244+
],
245+
(3, 13): ["_add_alias_", "_add_value_alias_"],
246+
}
242247

243248
DUNDER_PROPERTIES = [
244249
"__class__",

pylint/extensions/dunder.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ class DunderChecker(BaseChecker):
4141
)
4242

4343
def open(self) -> None:
44-
self._dunder_methods = (
45-
EXTRA_DUNDER_METHODS
46-
+ DUNDER_PROPERTIES
47-
+ self.linter.config.good_dunder_names
48-
)
44+
self._dunder_methods = DUNDER_PROPERTIES + self.linter.config.good_dunder_names
45+
for since_vers, extra_dunder_methods in EXTRA_DUNDER_METHODS.items():
46+
if since_vers <= self.linter.config.py_version:
47+
self._dunder_methods.extend(extra_dunder_methods)
4948
for since_vers, dunder_methods in DUNDER_METHODS.items():
5049
if since_vers <= self.linter.config.py_version:
5150
self._dunder_methods.extend(list(dunder_methods.keys()))

0 commit comments

Comments
 (0)