diff options
author | Sergey B Kirpichev <skirpichev@gmail.com> | 2022-03-29 09:37:42 +0300 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2022-03-29 10:42:23 +0200 |
commit | a880bd6d85d2487f509d1505b5146d608b15d870 (patch) | |
tree | 45c401e618aa2889fa28ceef586ea4f003084311 | |
parent | c73353064f934ae49472eb6138e1f8071b6b733e (diff) | |
download | pylint-git-a880bd6d85d2487f509d1505b5146d608b15d870.tar.gz |
Change 'nonexistent-operator' to allow repeated unary ops (with space or parens) (#6008)
Closes #5769
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | doc/whatsnew/2.13.rst | 5 | ||||
-rw-r--r-- | pylint/checkers/base/basic_error_checker.py | 1 | ||||
-rw-r--r-- | tests/functional/n/nonexistent_operator.py | 4 |
4 files changed, 15 insertions, 0 deletions
@@ -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? ============================ diff --git a/doc/whatsnew/2.13.rst b/doc/whatsnew/2.13.rst index b2c40e87e..51daf229d 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 e919344fe..242c13fa2 100644 --- a/pylint/checkers/base/basic_error_checker.py +++ b/pylint/checkers/base/basic_error_checker.py @@ -387,6 +387,7 @@ class BasicErrorChecker(_BasicChecker): (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 f05a64947..e092986bb 100644 --- a/tests/functional/n/nonexistent_operator.py +++ b/tests/functional/n/nonexistent_operator.py @@ -13,3 +13,7 @@ b = --a # [nonexistent-operator] b = a --a # [nonexistent-operator] c = (--a) * b # [nonexistent-operator] +c = -(-a) +c = +(+a) +c = - -a +c = + +a |