Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

superfluous-parens wrongly detected with walrus operator in list comprehensions #3383

Closed
jaysonsantos opened this issue Feb 3, 2020 · 2 comments · Fixed by #3697
Closed

Comments

@jaysonsantos
Copy link

Steps to reproduce

  1. Create a file a.py
  2. Paste this to it:
def is_odd(n):
    return n % 2 != 0 and n

print([odd for i in range(100) if (odd := is_odd(i))])
  1. run pylint a.py

Current behavior

************* Module a
a.py:5:0: C0325: Unnecessary parens after 'if' keyword (superfluous-parens)

------------------------------------------------------------------

Expected behavior

This should not complain about the parenthesis because without it the syntax is invalid when using the walrus := operator

pylint --version output

pylint 2.4.4
astroid 2.3.3
Python 3.8.0 (default, Oct 17 2019, 17:08:29) 
[Clang 11.0.0 (clang-1100.0.33.8)]
@PCManticore
Copy link
Contributor

Thanks for the report!

@PCManticore PCManticore changed the title superfluous-parens wrongly detected with walruns operator in list comprehensions superfluous-parens wrongly detected with walrus operator in list comprehensions Feb 4, 2020
@OJFord
Copy link

OJFord commented Feb 25, 2020

I most often encounter this with negated conditions:

if not (two_is_odd := is_odd(2)):
    # Handle two not being odd

(In this case of course it could be fixed by moving not inside the expression, but only because it returns bool.)

@brycepg brycepg self-assigned this Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 16, 2020
brycepg added a commit to brycepg/pylint that referenced this issue Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants