diff --git a/doc/whatsnew/fragments/8613.false_positive b/doc/whatsnew/fragments/8613.false_positive new file mode 100644 index 0000000000..80d28e9c23 --- /dev/null +++ b/doc/whatsnew/fragments/8613.false_positive @@ -0,0 +1,3 @@ +Fix a false positive for ``bad-dunder-name`` when there is a user-defined ``__index__`` method. + +Closes #8613 diff --git a/pylint/constants.py b/pylint/constants.py index ad7fc2256f..de29fb9b87 100644 --- a/pylint/constants.py +++ b/pylint/constants.py @@ -281,6 +281,7 @@ def _get_pylint_home() -> str: "__getnewargs_ex__", "__getnewargs__", "__getstate__", + "__index__", "__setstate__", "__reduce__", "__reduce_ex__", diff --git a/tests/functional/ext/bad_dunder/bad_dunder_name.py b/tests/functional/ext/bad_dunder/bad_dunder_name.py index 48247aba03..6008866b1d 100644 --- a/tests/functional/ext/bad_dunder/bad_dunder_name.py +++ b/tests/functional/ext/bad_dunder/bad_dunder_name.py @@ -49,6 +49,9 @@ def __private_method(self): def __doc__(self): return "Docstring" + def __index__(self): + return 1 + def __increase_me__(val): return val + 1