diff --git a/ChangeLog b/ChangeLog index e7a9cb06e1..f4ee7f1f61 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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? ============================ diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst index b2c40e87e0..51daf229d5 100644 --- a/doc/whatsnew/2.13.rst +++ b/doc/whatsnew/2.13.rst @@ -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 diff --git a/pylint/checkers/base/basic_error_checker.py b/pylint/checkers/base/basic_error_checker.py index e919344fec..242c13fa2e 100644 --- a/pylint/checkers/base/basic_error_checker.py +++ b/pylint/checkers/base/basic_error_checker.py @@ -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) diff --git a/tests/functional/n/nonexistent_operator.py b/tests/functional/n/nonexistent_operator.py index f05a649478..e092986bb6 100644 --- a/tests/functional/n/nonexistent_operator.py +++ b/tests/functional/n/nonexistent_operator.py @@ -13,3 +13,7 @@ b = a --a # [nonexistent-operator] c = (--a) * b # [nonexistent-operator] +c = -(-a) +c = +(+a) +c = - -a +c = + +a