Skip to content

Commit a880bd6

Browse files
Change 'nonexistent-operator' to allow repeated unary ops (with space or parens) (#6008)
Closes #5769 Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent c733530 commit a880bd6

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ Release date: TBA
2828

2929
Closes #5998
3030

31+
* Fix false positive for 'nonexistent-operator' when repeated '-' are
32+
separated (e.g. by parens).
33+
34+
Closes #5769
35+
3136

3237
What's New in Pylint 2.13.2?
3338
============================

doc/whatsnew/2.13.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,8 @@ Other Changes
566566
"return (a or b) in iterable".
567567

568568
Closes #5803
569+
570+
* Fix false positive for 'nonexistent-operator' when repeated '-' are
571+
separated (e.g. by parens).
572+
573+
Closes #5769

pylint/checkers/base/basic_error_checker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ def visit_unaryop(self, node: nodes.UnaryOp) -> None:
387387
(node.op in "+-")
388388
and isinstance(node.operand, nodes.UnaryOp)
389389
and (node.operand.op == node.op)
390+
and (node.col_offset + 1 == node.operand.col_offset)
390391
):
391392
self.add_message("nonexistent-operator", node=node, args=node.op * 2)
392393

tests/functional/n/nonexistent_operator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@
1313
b = a
1414
--a # [nonexistent-operator]
1515
c = (--a) * b # [nonexistent-operator]
16+
c = -(-a)
17+
c = +(+a)
18+
c = - -a
19+
c = + +a

0 commit comments

Comments
 (0)