Skip to content

Commit c2d42ba

Browse files
clavedelunacdce8p
authored andcommitted
Remove __index__ from unnecessary-dunder-call check (#7650)
1 parent e8dc9b6 commit c2d42ba

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/whatsnew/fragments/6795.bugfix

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove ``__index__`` dunder method call from ``unnecessary-dunder-call`` check.
2+
3+
Closes #6795

pylint/checkers/dunder_methods.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
"__complex__": "Use complex built-in function",
101101
"__int__": "Use int built-in function",
102102
"__float__": "Use float built-in function",
103-
"__index__": "Use index method",
104103
"__round__": "Use round built-in function",
105104
"__trunc__": "Use math.trunc function",
106105
"__floor__": "Use math.floor function",
@@ -125,7 +124,8 @@ class DunderCallChecker(BaseChecker):
125124
We exclude __new__, __subclasses__, __init_subclass__, __set_name__,
126125
__class_getitem__, __missing__, __exit__, __await__,
127126
__aexit__, __getnewargs_ex__, __getnewargs__, __getstate__,
128-
__setstate__, __reduce__, __reduce_ex__
127+
__setstate__, __reduce__, __reduce_ex__,
128+
and __index__ (see https://github.com/PyCQA/pylint/issues/6795)
129129
since these either have no alternative method of being called or
130130
have a genuine use case for being called manually.
131131

tests/functional/u/unnecessary/unnecessary_dunder_call.py

+6
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,9 @@ def get_first_subclass(cls):
122122
# since we can't apply alternate operators/functions here.
123123
a = [1, 2, 3]
124124
assert super(type(a), a).__str__() == "[1, 2, 3]"
125+
126+
class MyString(str):
127+
"""Custom str implementation"""
128+
def rjust(self, width, fillchar= ' '):
129+
"""Acceptable call to __index__"""
130+
width = width.__index__()

0 commit comments

Comments
 (0)