Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10435.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add Enum dunder methods ``_generate_next_value_``, ``_missing_``, ``_numeric_repr_``, ``_add_alias_``, and ``_add_value_alias_`` to the list passed to ``--good-dunder-names``.

Closes #10435
45 changes: 25 additions & 20 deletions pylint/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,26 +219,31 @@ def _get_pylint_home() -> str:
"__anext__": "Use anext built-in function",
},
}

EXTRA_DUNDER_METHODS = [
"__new__",
"__subclasses__",
"__init_subclass__",
"__set_name__",
"__class_getitem__",
"__missing__",
"__exit__",
"__await__",
"__aexit__",
"__getnewargs_ex__",
"__getnewargs__",
"__getstate__",
"__index__",
"__setstate__",
"__reduce__",
"__reduce_ex__",
"__post_init__", # part of `dataclasses` module
]
EXTRA_DUNDER_METHODS: dict[tuple[int, int], list[str]] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it could be tuple[str] since we have no need to mutate this anywhere in the code; but I don't feel too strongly about changing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @mbyrnepr2, I think that'll work too but it'll be tuple[str, str] and we'll need to keep extending it if we add more values to the tuple, so I'm not sure it's worth it as this constant is used very little already.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
EXTRA_DUNDER_METHODS: dict[tuple[int, int], list[str]] = {
EXTRA_DUNDER_METHODS: dict[tuple[int, int], tuple[str, ...]] = {

Would this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I think that will work. Thank you for the suggestion.

(0, 0): [
"__new__",
"__subclasses__",
"__init_subclass__",
"__set_name__",
"__class_getitem__",
"__missing__",
"__exit__",
"__await__",
"__aexit__",
"__getnewargs_ex__",
"__getnewargs__",
"__getstate__",
"__index__",
"__setstate__",
"__reduce__",
"__reduce_ex__",
"__post_init__", # part of `dataclasses` module
"_generate_next_value_",
"_missing_",
"_numeric_repr_",
],
(3, 13): ["_add_alias_", "_add_value_alias_"],
}

DUNDER_PROPERTIES = [
"__class__",
Expand Down
9 changes: 4 additions & 5 deletions pylint/extensions/dunder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ class DunderChecker(BaseChecker):
)

def open(self) -> None:
self._dunder_methods = (
EXTRA_DUNDER_METHODS
+ DUNDER_PROPERTIES
+ self.linter.config.good_dunder_names
)
self._dunder_methods = DUNDER_PROPERTIES + self.linter.config.good_dunder_names
for since_vers, extra_dunder_methods in EXTRA_DUNDER_METHODS.items():
if since_vers <= self.linter.config.py_version:
self._dunder_methods.extend(extra_dunder_methods)
for since_vers, dunder_methods in DUNDER_METHODS.items():
if since_vers <= self.linter.config.py_version:
self._dunder_methods.extend(list(dunder_methods.keys()))
Expand Down
Loading