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 in if-expression are not superfluous #2818

Closed
andreasvc opened this issue Mar 18, 2019 · 2 comments · Fixed by #4784
Closed

superfluous-parens in if-expression are not superfluous #2818

andreasvc opened this issue Mar 18, 2019 · 2 comments · Fixed by #4784
Labels
Milestone

Comments

@andreasvc
Copy link

andreasvc commented Mar 18, 2019

Steps to reproduce

Create file t.py:

def f(b):
    return [a for a in (b if b else [b])]

Related to #574 but this example has an if-expression instead of short circut.

Current behavior

t.py:2:0: C0325: Unnecessary parens after 'in' keyword (superfluous-parens)

Note that following this suggestion actually creates a SyntaxError:

def g(b):
    return [a for a in b if b else [b]]
t.py:2:0: E0001: invalid syntax (<unknown>, line 2) (syntax-error)

Expected behavior

This warning is not emitted in this case.

pylint --version output

pylint 2.3.1
astroid 2.2.5
Python 3.7.2+ (default, Feb 27 2019, 15:41:59) 
[GCC 8.2.0]
@andreasvc andreasvc changed the title superfluous-parents which are not superfluous superfluous-parens in if-expression are not superfluous Mar 18, 2019
@PCManticore
Copy link
Contributor

Thanks @andreasvc for reporting this issue.

@p-l-
Copy link

p-l- commented Jan 2, 2021

I'm also having this bug in an expression that matches @andreasvc's pattern:

   rec["answers"] = [elt.lower() for elt in (rec["answers"] if rec["answers"] else [])]

DanielNoord added a commit to DanielNoord/pylint that referenced this issue Aug 1, 2021
This fixes the false positives identified in pylint-dev#2818, pylint-dev#3249, pylint-dev#3608 & pylint-dev#4346
All false positives reported fell under keywords before walrus operator
or if-keyword within generators/comprehension.
This closes pylint-dev#2818, closes pylint-dev#3429, closes pylint-dev#3608, closes pylint-dev#4346
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.10.0 milestone Aug 1, 2021
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Aug 1, 2021
This fixes the false positives identified in pylint-dev#2818, pylint-dev#3249, pylint-dev#3608 & pylint-dev#4346
All false positives reported fell under keywords before walrus operator
or if-keyword within generators/comprehension.
This closes pylint-dev#2818, closes pylint-dev#3429, closes pylint-dev#3608, closes pylint-dev#4346
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Aug 1, 2021
This fixes the false positives identified in pylint-dev#2818, pylint-dev#3249, pylint-dev#3608 & pylint-dev#4346
All false positives reported fell under keywords before walrus operator
or if-keyword within generators/comprehension.
This closes pylint-dev#2818, closes pylint-dev#3429, closes pylint-dev#3608, closes pylint-dev#4346
Pierre-Sassoulas added a commit that referenced this issue Aug 3, 2021
* Split functional tests for ``superfluous-parents``

* Fix false positives for superfluous-parens
This fixes the false positives identified in #2818, #3249, #3608 & #4346
All false positives reported fell under keywords before walrus operator
or if-keyword within generators/comprehension.
This closes #2818, closes #3429, closes #3608, closes #4346

* Move the superfluous functional tests to functional/s/super

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants