Skip to content

Commit

Permalink
Remove __index__ from unnecessary-dunder-call check (#7650)
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Oct 20, 2022
1 parent 5b7265b commit 15dd079
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/6795.bugfix
@@ -0,0 +1,3 @@
Remove ``__index__`` dunder method call from ``unnecessary-dunder-call`` check.

Closes #6795
4 changes: 2 additions & 2 deletions pylint/checkers/dunder_methods.py
Expand Up @@ -100,7 +100,6 @@
"__complex__": "Use complex built-in function",
"__int__": "Use int built-in function",
"__float__": "Use float built-in function",
"__index__": "Use index method",
"__round__": "Use round built-in function",
"__trunc__": "Use math.trunc function",
"__floor__": "Use math.floor function",
Expand All @@ -125,7 +124,8 @@ class DunderCallChecker(BaseChecker):
We exclude __new__, __subclasses__, __init_subclass__, __set_name__,
__class_getitem__, __missing__, __exit__, __await__,
__aexit__, __getnewargs_ex__, __getnewargs__, __getstate__,
__setstate__, __reduce__, __reduce_ex__
__setstate__, __reduce__, __reduce_ex__,
and __index__ (see https://github.com/PyCQA/pylint/issues/6795)
since these either have no alternative method of being called or
have a genuine use case for being called manually.
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/u/unnecessary/unnecessary_dunder_call.py
Expand Up @@ -122,3 +122,9 @@ def get_first_subclass(cls):
# since we can't apply alternate operators/functions here.
a = [1, 2, 3]
assert super(type(a), a).__str__() == "[1, 2, 3]"

class MyString(str):
"""Custom str implementation"""
def rjust(self, width, fillchar= ' '):
"""Acceptable call to __index__"""
width = width.__index__()

0 comments on commit 15dd079

Please sign in to comment.