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

Fix false-positive consider-using-with for ternary conditionals in with items #4679

Merged

Conversation

DudeNr33
Copy link
Collaborator

@DudeNr33 DudeNr33 commented Jul 6, 2021

Steps

  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature or an important bug fix, add a What's New entry in
    doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Description

For details see #4676 - things like open calls inside ternary conditionals used in a with were incorrectly flagged with the consider-using-with, because the check if this call happens inside the items of a with only looked at the first parent node.
This is now expanded to check all parents until we reach the enclosing frame.

I also ran pylint over a few other codebases (black, requests, pip, twine) and (luckily 😁) found no new edge cases.
But I somehow have a feeling that this won't stay the last fix of false-positives for consider-using-with...

Type of Changes

Type
🐛 Bug fix

Related Issue

Closes #4676

… with, it is not enough to just check the first parent node to determine if the call is happening inside a with.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.006%) to 92.051% when pulling 0708099 on DudeNr33:fix-4676-false-positive-r1732 into 0f8212f on PyCQA:main.

@Pierre-Sassoulas Pierre-Sassoulas added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jul 6, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.4 milestone Jul 6, 2021
@DudeNr33 DudeNr33 marked this pull request as ready for review July 6, 2021 19:24
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be other use case but I think this is converging fast 😉 Thanks for fixing this so fast, much appreciated !

@Pierre-Sassoulas Pierre-Sassoulas merged commit e4cd2ef into pylint-dev:main Jul 6, 2021
@DudeNr33 DudeNr33 deleted the fix-4676-false-positive-r1732 branch July 7, 2021 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive consider-using-with on a with statement
3 participants