Skip to content

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

Closed
@jaysonsantos

Description

@jaysonsantos

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)]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions