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

False positive superfluous-parens #4907

Closed
jolaf opened this issue Aug 24, 2021 · 7 comments · Fixed by #4948
Closed

False positive superfluous-parens #4907

jolaf opened this issue Aug 24, 2021 · 7 comments · Fixed by #4948
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@jolaf
Copy link

jolaf commented Aug 24, 2021

Bug description

tuple(x for x in ((a, str(a)) for a in ()))

Command used

pylint test.py

Pylint output

************* Module test
test.py:1: [C0325(superfluous-parens), ] Unnecessary parens after 'in' keyword

Expected behavior

No errors.

Pylint version

pylint 2.10.2
astroid 2.7.2
Python 3.8.10 (default, Jun  2 2021, 10:49:15) 
[GCC 9.4.0]

OS / Environment

Ubuntu 20.04.3 LTS

@jolaf jolaf added Bug 🪲 Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 24, 2021
@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Aug 24, 2021
@SamyCookie
Copy link

SamyCookie commented Aug 25, 2021

similar regression since 2.10 version with the following example:

    def __iter__(self):
        return ( (k, getattr(self, k)) for k in self.keys )

@DanielNoord
Copy link
Collaborator

@Pierre-Sassoulas This is the result of the following tests and my implementation of solving these in #4784

B = [x for x in ((3, 4))]  # [superfluous-parens]
C = [x for x in ((3, 4) if 1 > 0 else (5, 6))]
D = [x for x in ((3, 4) if 1 > 0 else ((5, 6)))]  # [superfluous-parens]
E = [x for x in ((3, 4) if 1 > 0 else ((((5, 6)))))]  # [superfluous-parens]

Looking at these two reports perhaps these are valid cases of double parens and should be removed from the tests, as well as removing from pylint/checkers/format.py.

                    if contains_double_parens and tokens[i + 1].string == ")":
                        self.add_message(
                            "superfluous-parens", line=line_num, args=keyword_token
                        )
                        return
                    contains_double_parens = 0
                    continue

@trym-b
Copy link

trym-b commented Aug 31, 2021

I think I hit this issue as well, with this code block, altough with the return keyword instead of in

import numpy as np


def _function_one(var_1: int, var_2: int) -> np.ndarray:
    result = (((var_1 & var_2)) > 0)
    return result.astype(np.float32) # no problem


def _function_two(var_1: int, var_2: int) -> np.ndarray:
    return (((var_1 & var_2)) > 0).astype(np.float32) # Error: Unnecessary parens after 'return' keyword (superfluous-parens)
test_pylint.py:10:0: C0325: Unnecessary parens after 'return' keyword (superfluous-parens)
$ pylint --version
pylint 2.10.2
astroid 2.7.3
Python 3.9.5 (default, May 19 2021, 11:32:47) 
[GCC 9.3.0]

@DanielNoord
Copy link
Collaborator

@Pierre-Sassoulas I think you might have missed this. I believe this should be part of 2.11 as it was introduced in 2.10 and is easily fixable (if we do agree that this part of the check should be removed).

@Pierre-Sassoulas
Copy link
Member

Right, thank you for reminding me. The suggestion in your previous comment makes sense.

DanielNoord added a commit to DanielNoord/pylint that referenced this issue Sep 1, 2021
Tuples can be created with inner tuples. This creates double parenthesis
which we flagged incorrectly.
This closes pylint-dev#4907
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.11.0 milestone Sep 1, 2021
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Sep 1, 2021
Tuples can be created with inner tuples. This creates double parenthesis
which we flagged incorrectly.
This closes pylint-dev#4907
Pierre-Sassoulas pushed a commit that referenced this issue Sep 1, 2021
Tuples can be created with inner tuples. This creates double parenthesis
which we flagged incorrectly.
This closes #4907
@eli-schwartz
Copy link

I hit this issue too at https://github.com/mesonbuild/meson/blob/dc51740e2cdee171ac6ebc7ed261e5c08730c9a9/mesonbuild/dependencies/mpi.py#L150-L152

            return (f.startswith(('-L', '-l', '-Xlinker')) or
                    f == '-pthread' or
                    (f.startswith('-W') and f != '-Wall' and not f.startswith('-Werror')))

The parentheses are needed for grouping, the alternative is a syntax error. This doesn't appear to have been mentioned already in this bug, and it's fixed by the linked ticket, but there doesn't seem to be a test explicitly covering this. Maybe there should be?

@DanielNoord
Copy link
Collaborator

Yeah, this seems like something different than any of our other tests! I will add an test when I get around to it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants