Problematic rule is Python static code analysis: Parentheses should not be used after certain keywords Parentheses should not be used after certain keywords. In code view it says “Remove the parentheses after this “not” keyword.”.
Sample code (I don’t think more context is necessary):
if not (article_tag := soup.find("article")): ...
Sonar reports to remove parentheses around walrus operator assignment. This isn’t a valid issue in Python 3.8 (at least) because removing parentheses causes
SyntaxError (run through
E File "/home/some/path/file.py.", line 9999 E if not article_tag := soup.find("article"): E ^ E SyntaxError: cannot use assignment expressions with operator
not keyword in non-parentheses version “solves”
SyntaxError but changing condition is not a valid solution here. Parentheses are required.