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

superfluous-parens false positive for is not tests #5930

Closed
ryansdowning opened this issue Mar 17, 2022 · 2 comments · Fixed by #6451
Closed

superfluous-parens false positive for is not tests #5930

ryansdowning opened this issue Mar 17, 2022 · 2 comments · Fixed by #6451
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Help wanted 🙏 Outside help would be appreciated, good for new contributors
Milestone

Comments

@ryansdowning
Copy link

ryansdowning commented Mar 17, 2022

Bug description

I just got the lint C0325: Unnecessary parens after 'not' keyword (superfluous-parens), so I removed the parens it referred to, but thankfully a unit test caught that these are not the same, and the parens are needed (removing them changes the logic!).

I have been able to create a minimal example that I believe reproduces this

In [1]: (None is None) is not (None == 1)  # Original, pylint lints with C0325
Out[1]: True

In [1]: (None is None) is not None == 1  # Recommended by C0325
Out[1]: False

Configuration

No response

Command used

pylint path/to/pkg/ --max-line-length=120 --fail-under=9 --load-plugins pylint_django

Pylint output

************* Module pkg.module
path/to/pkg/module.py:63:0: C0325: Unnecessary parens after 'not' keyword (superfluous-parens)

Expected behavior

C0325 should not be output here.

Pylint version

pylint 2.11.1
astroid 2.8.6
Python 3.9.7 (default, Sep 16 2021, 13:09:58) 
[GCC 7.5.0]

OS / Environment

No response

Additional dependencies

No response

@ryansdowning ryansdowning added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Mar 17, 2022
@jacobtylerwalls
Copy link
Member

Thanks for the report. This is not a duplicate of #5803 (my diff for that doesn't fix this!)

There are numerous operators that aren't working. At a glance, it looks like the implementation of the check confuses is not with not, which have different precedences. That would explain why the operators in the same group as is not produce false positives:

x is not (x <= y)
True is not (True == False)
True is not (True is not False)

@jacobtylerwalls jacobtylerwalls added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Mar 17, 2022
@jacobtylerwalls jacobtylerwalls changed the title C0325 False Positive superfluous-parens False Positive for is not tests Mar 17, 2022
@jacobtylerwalls jacobtylerwalls changed the title superfluous-parens False Positive for is not tests superfluous-parens false positive for is not tests Mar 17, 2022
@jacobtylerwalls jacobtylerwalls added the Help wanted 🙏 Outside help would be appreciated, good for new contributors label Mar 30, 2022
@timmartin
Copy link
Contributor

If I understand correctly, the problem isn't so much that not and is not have different precedence (they are different, but no other operator is between them), but that the formatting checker assumes that a not necessarily indicates a unary operator when in fact it can be part of a binary operator expression in the form of is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Help wanted 🙏 Outside help would be appreciated, good for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants