Issue 4430 false positive consider-using-with R1732 #4453
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Steps
Description
consider-using-with
was triggered when the resource allocating operation was performed inside a custom context manager.This is a false positive and reported in #4430.
This PR changes the behavior so that the message is suppressed if the call or assignment is made inside
__enter__
or inside a function decorated with@contextlib.contextmanager
.This PR does not address the proposed warning of #4430, which should trigger if a resource is allocated in
__enter__
but not released afterwards in__exit__
. This should be tracked with a new enhancement issue.Type of Changes
Related Issue
Closes #4430