Skip to content

Commit

Permalink
Merge 94f9363 into 3140696
Browse files Browse the repository at this point in the history
  • Loading branch information
timmartin committed Apr 27, 2022
2 parents 3140696 + 94f9363 commit 4d4ae91
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ Release date: TBA

Closes #4324

* Avoid reporting ``superfluous-parens`` on expressions using the ``is not`` operator.

Closes #5930

* Added the ``super-without-brackets`` checker, raised when a super call is missing its brackets.

Closes #4008
Expand Down
4 changes: 4 additions & 0 deletions doc/whatsnew/2.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,10 @@ Other Changes

Closes #5931

* Avoid reporting ``superfluous-parens`` on expressions using the ``is not`` operator.

Closes #5930

* Fix a crash when linting a file that passes an integer ``mode=`` to
``open``

Expand Down
10 changes: 9 additions & 1 deletion pylint/checkers/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ def _check_keyword_parentheses(
self._bracket_stack.pop()
if tokens[start + 1].string != "(":
return
if (
tokens[start].string == "not"
and start > 0
and tokens[start - 1].string == "is"
):
# If this is part of an `is not` expression, we have a binary operator
# so the parentheses are not necessarily redundant.
return
found_and_or = False
contains_walrus_operator = False
walrus_operator_depth = 0
Expand Down Expand Up @@ -363,7 +371,7 @@ def _check_keyword_parentheses(
elif token[1] == "for":
return
# A generator expression can have an 'else' token in it.
# We check the rest of the tokens to see if any problems incur after
# We check the rest of the tokens to see if any problems occur after
# the 'else'.
elif token[1] == "else":
if "(" in (i.string for i in tokens[i:]):
Expand Down
7 changes: 7 additions & 0 deletions tests/functional/s/superfluous_parens.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,10 @@ class ClassA:

def __iter__(self):
return ((k, getattr(self, k)) for k in self.keys)

if (A == 2) is not (B == 2):
pass

M = A is not (A <= H)
M = True is not (M == K)
M = True is not (True is not False)

0 comments on commit 4d4ae91

Please sign in to comment.