Skip to content

Commit

Permalink
Change 'nonexistent-operator' to allow repeated unary ops (with space…
Browse files Browse the repository at this point in the history
… or parens) (#6008)

Closes #5769

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
skirpichev and Pierre-Sassoulas authored Mar 29, 2022
1 parent 44ddbdf commit 0227e7f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ Release date: TBA

Closes #5998

* Fix false positive for 'nonexistent-operator' when repeated '-' are
separated (e.g. by parens).

Closes #5769


What's New in Pylint 2.13.2?
============================
Expand Down
5 changes: 5 additions & 0 deletions doc/whatsnew/2.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,8 @@ Other Changes
"return (a or b) in iterable".

Closes #5803

* Fix false positive for 'nonexistent-operator' when repeated '-' are
separated (e.g. by parens).

Closes #5769
1 change: 1 addition & 0 deletions pylint/checkers/base/basic_error_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ def visit_unaryop(self, node: nodes.UnaryOp) -> None:
(node.op in "+-")
and isinstance(node.operand, nodes.UnaryOp)
and (node.operand.op == node.op)
and (node.col_offset + 1 == node.operand.col_offset)
):
self.add_message("nonexistent-operator", node=node, args=node.op * 2)

Expand Down
4 changes: 4 additions & 0 deletions tests/functional/n/nonexistent_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
b = a
--a # [nonexistent-operator]
c = (--a) * b # [nonexistent-operator]
c = -(-a)
c = +(+a)
c = - -a
c = + +a

0 comments on commit 0227e7f

Please sign in to comment.