Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove __index__ from unnecessary-dunder-call check #7650

Merged
merged 2 commits into from
Oct 20, 2022
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/6795.bugfix
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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__()