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 committed Mar 29, 2022
1 parent c733530 commit a880bd6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Expand Up @@ -28,6 +28,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
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
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
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 a880bd6

Please sign in to comment.