Inconsistent determination of statements with no effect and possible suppression
In Python, I am implementing a class that implements certain operators, including __gt__ (>) and __add__ (+). Both have side effects. Using IntelliJ with the Python plugin, I get a warning that the statement with > does not have an effect (which is true for the usual non-side effect implementation). This does not happen for +.
So there seem to be two problems: PyCharm can't detect when dunder functions cause side effects and thus wrongly assumed no effect when no assignment takes place. Secondly, it is inconsistent between different operators, unless I am mistaken and __add__ normally does cause side effects.
Since I hope to distribute this class to other people, I was wondering if there is a solution for the first problem, so that they don't get false warnings.
Here is a minimal viable code example.
class A:
def __gt__(self, other):
self.gt = other
def __add__(self, other):
self.add = other
a = A()
a > a # Warning: statement seems to have no effect
a + a # No warning
Please sign in to leave a comment.
I've modified your code a bit to better demonstrate the issue:
Running the code outputs both prints so the statement does have an effect, while PyCharm shows the false-positive. I've submitted a bug report based on your case: https://youtrack.jetbrains.com/issue/PY-39323
Feel free to comment.
Thank you for submitting the report! It was not accepted but at least considered.