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
Incorrectly identifying parens as superfluous in comprehensions with ternary operators #3608
Comments
Thank you for creating the issue, I can reproduce it on the latest pylint. |
@brycepg so I'm not sure that those are the source of this bug. I think the error is triggered by this line https://github.com/PyCQA/pylint/blob/master/pylint/checkers/format.py#L421. It looks to me like there needs to be another block here https://github.com/PyCQA/pylint/blob/master/pylint/checkers/format.py#L436-L441 to handle the case where parens are required around a conditional statement. To ensure that statements like |
My bad I commented on the wrong issue |
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
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
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
* 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>
Pylint incorrectly identifies parens as superfluous when they are used to isolate a ternary operator that determines the iterable inside of a list comprehension (or set comprehension, dict comprehension etc.).
Steps to reproduce
scratch.py
with contents:$ pylint scratch.py --enable=all
Current behavior
Pylint reports that there is one issue with this code:
scratch.py:3:0: C0325: Unnecessary parens after 'in' keyword (superfluous-parens)
Expected behavior
Pylint should report no issues with this code since the parenthesis are required. Following Pylints suggestion and changing the file to:
results in invalid Python code:
pylint --version output
The text was updated successfully, but these errors were encountered: