-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
False positive unnecessary-dunder-call for __iadd__ #8978
Comments
What about adding the """https://github.com/pylint-dev/pylint/issues/8978"""
class Incrementable:
"""class with an incrementable field"""
def __init__(self, a):
self.a = a
def __add__(self, other):
return self.__iadd__(other)
def __iadd__(self, other):
if isinstance(other, Incrementable):
self.a += other.a
return self
return NotImplemented
d = {}
d.setdefault("a", Incrementable(6) + Incrementable(7)) |
Following the suggestion given by the warning results in code that fails to parse: d.setdefault("a", Incrementable(6)) += Incrementable(7) # Use += operator
|
Yes, but I think the message should be modified and still raised (in order to make the code more pythonic like in my proposed snippet). Something like 'create an |
this does not modify
is not the same as
IOW, this code is NOT equivalent to the code that I posted in all cases. |
Bug description
the following code generates an
unnecessary-dunder-call
messageI see 2 work-arounds, both pollute the namespace:
operator
:Using
defaultdict
is even worse - I will have to convert it back to the ordinary dict for serialization...Configuration
No response
Command used
Pylint output
************* Module z z.py:14:0: C2801: Unnecessarily calls dunder method __iadd__. Use += operator. (unnecessary-dunder-call)
Expected behavior
no diagnostics - or better one.
since
+=
requires an extra variable, it is not an acceptable recommendation.Pylint version
OS / Environment
windows, linux
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: