Description
An if
statement that tests a negated (not
) parenthesized Assignment Expression without any other operators (See "Non-issues" section below) is reported by Pylint to have superfluous parentheses.
I believe this is a false positive. Removing the parentheses is invalid syntax.
Steps to reproduce
- Write an if statement that tests a negated (
not
) Assignment Expression, such as:
if not (my_var := False):
print(my_var)
- Run pylint against that code.
Current behavior
Pylint reports superfluous-parens:Unnecessary parens after 'not' keyword
.
Expected behavior
Pylint should not report about this syntax.
Removing the parentheses is a syntax error: SyntaxError: cannot use named assignment with operator
.
pylint --version output
pylint 2.4.4
astroid 2.3.3
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)]
Non-issues
-
If the negated assignment-expression
if
statement contains another binary operator, no Pylint report is generated about it. (Or at least, that seems to be the only difference.)For example, this slightly-modified snippet from What’s New In Python 3.8 does not cause Pylint to report:
if not (n := len(list(range(11))) > 10: print(f"List is too long ({n} elements, expected <= 10)")