Parentheses around generator expression important after "return" keyword

SonarLint plugin 4.3.0.3495 installed on PyCharm suggests to

Remove the parentheses after this “return” keyword.

(python:S1721) even when the parentheses surround a generator expression and therefore cannot and should not be removed.

Code to reproduce:

def foo():
    return (x**2 for x in range(5))

Hi @tomasssalles,

Welcome to our community!

Next release of SonarLint will include latest version of Python analyzer, where this False Positive has been fixed.

In the meanwhile, as a workaround, I’d suggest to use SonarLint in connected mode with SonarCloud, so that you can benefit from running the latest Python analyzer.

Great! Thanks.