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 negatives superfluous-parens with superfluous parenthesis on function call #5334

Open
KotlinIsland opened this issue Nov 18, 2021 · 7 comments
Labels
Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@KotlinIsland
Copy link
Contributor

KotlinIsland commented Nov 18, 2021

Current problem

print((((((((((((((((((((((((((((((1))))))))))))))))))))))))))))))

This looks cringe to me. I want a pylint warning.

@KotlinIsland KotlinIsland added Enhancement ✨ Improvement to a component Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 18, 2021
@DanielNoord
Copy link
Collaborator

We actually had a similar checker (contributed by me), which I removed in #4948

It is actually (almost) impossible to determine when a tuple with inner tuple is superfluous or when it is intended. We risk throwing a lot of false positives for valid use cases of inner tuples. We could make a check that checks whether the tuples are in a non-sensical place, such as the print call in the example, but I think that might also be unmaintainable. We would need a USELESS_INNER_TUPLE_FUNCTIONS variable or something and I'm not sure if we won't still throw many false positives.
If anybody thinks they have a good idea for this while also limiting false positives we could go ahead (and you can probably copy code from #4948). However, I would argue to close this issue as it might be difficult to implement this satisfactorily.

@Pierre-Sassoulas Pierre-Sassoulas added Discussion 🤔 High effort 🏋 Difficult solution or problem to solve and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 18, 2021
@Pierre-Sassoulas
Copy link
Member

Please read #4907 before participating to the discussion in this issue.

@KotlinIsland
Copy link
Contributor Author

image
PyCharm correctly handles all of these scenarios.

@KotlinIsland
Copy link
Contributor Author

@DanielNoord is 'superfluous-parens' removed entirely? I can't get it to trigger under any circumstances. Your comment suggests that it is removed, but that's not in the changelog and 'superfluous-parens' is listed in the enabled messages.

@KotlinIsland
Copy link
Contributor Author

KotlinIsland commented Nov 19, 2021

OHHHHHHHHHHHHH, it only detects single unnecessary parens

for (i) in ([1]):  # superfluous-parens
    print(i)

for ((i)) in (([1])):  # no warning
    print(i)

@DanielNoord
Copy link
Collaborator

Oh, I think you might have found a nice first step towards this:
Raise superfluous-parens on nested parens if the message would be triggered on single parens.

Looking at your example that is currently not the case!

@Pierre-Sassoulas Pierre-Sassoulas changed the title Add new checker: redundant-parenthesis False negatives superfluous-parens with more than one superfluous parenthesis Nov 19, 2021
@KotlinIsland
Copy link
Contributor Author

This seems like something that would be absurdly simple if a CST was used instead of analyzing the raw tokens.

@KotlinIsland KotlinIsland changed the title False negatives superfluous-parens with more than one superfluous parenthesis False negatives superfluous-parens with superfluous parenthesis on function call Nov 22, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Discussion 🤔 High effort 🏋 Difficult solution or problem to solve labels Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

3 participants