Skip to content

Fix superfluous-parens false negative for and/or conditions - #11190

Open
skdas20 wants to merge 1 commit into
pylint-dev:mainfrom
skdas20:fix-10084-superfluous-parens-and-or
Open

skdas20 wants to merge 1 commit into
pylint-dev:mainfrom
skdas20:fix-10084-superfluous-parens-and-or

Conversation

@skdas20

@skdas20 skdas20 commented Jul 26, 2026

Copy link
Copy Markdown

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

superfluous-parens (C0325) gave a blanket pass to any parenthesised expression containing and/or, so conditions like if (a is None and a is not None): were never reported β€” even though the same expression without boolean operators (e.g. if (a == 5): or K = ("a" + "b")) is reported. This makes the and/or exemption narrower, keeping it only where the parentheses are genuinely required:

  • after not β€” not (a and b) parses differently without parens;
  • when the parenthesised expression is an operand of a following binary operator β€” e.g. (a or b) in c.

Parentheses that wrap the entire statement expression (if (a and b):, while (a or b):) are now reported. Multiline conditions are untouched (the existing NL bail-out), as are partial groupings like if (a and b) or c:.

This follows the same "narrow the historical blanket pass" approach as #11081 did for in, which left this case explicitly out of scope. Existing functional suite passes (900 tests), and running the updated check over pylint's own source produces no new hits (the three pre-existing C0325 hits on main are unchanged by this PR).

Note: #10084 is assigned to @ranadheerg β€” I asked on the issue whether they're still working on it before opening this; happy to close this in favor of their PR if they are.

Closes #10084

Parentheses wrapping an entire and/or condition (e.g. 'if (a and b):')
are now reported. The blanket found_and_or pass is kept only where the
parentheses are genuinely required: after 'not', and when the
parenthesised expression is an operand of a following binary operator
such as 'in'.

Closes pylint-dev#10084
@skdas20

skdas20 commented Aug 8, 2026

Copy link
Copy Markdown
Author

Assignment question on #10084 is resolved β€” @ranadheerg has handed it over (#10084 (comment)), so this is no longer stepping on anyone's work and is ready for review whenever someone has a moment.

Recapping the state since it's been open a little while: superfluous-parens gave a blanket pass to any parenthesised expression containing and/or, so if (a is None and a is not None): was never reported even though if (a == 5): is. This narrows that exemption to the cases where the parentheses are genuinely required β€” after not, and where the parenthesised expression is an operand of a following binary operator β€” following the same approach #11081 used for in.

All 900 functional tests pass, and running the updated check over pylint's own source yields no new hits beyond the three already present on main. The primer will surface new messages on external code, which is expected for a false-negative fix β€” happy to walk through any that look wrong.

@Pierre-Sassoulas Pierre-Sassoulas added the False Negative πŸ¦‹ No message is emitted but something is wrong with the code label Oct 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

False Negative πŸ¦‹ No message is emitted but something is wrong with the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False negative superfluous-parens when around two conditional and an and

2 participants