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 4689 Exclude ThreadPoolExecutor and ProcessPoolExecutor from consider-using-with #4721

Merged

Conversation

DudeNr33
Copy link
Collaborator

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

This PR addresses two issues:

  • Completely exclude ThreadPoolExecutor and ProcessPoolExecutor from consider-using-with, as consider-using-with on ThreadPoolExecutor?Β #4689 points out that legitimate use cases exist where they are used without a with block.
  • Check if a context manager that was assigned to a variable is used later on in a with block. Therefore, the following (although unusual, there are probably better examples for this) will no longer emit a consider-using-with message:
file_handle = open("foo")  # formerly triggered ``consider-using-with``, not anymore now
with file_handle:
    content = file_handle.read()

Type of Changes

Type
βœ“ πŸ› Bug fix
βœ“ πŸ”¨ Refactoring

Related Issue

Closes #4689

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.9.4 milestone Jul 19, 2021
@Pierre-Sassoulas Pierre-Sassoulas added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jul 19, 2021
@coveralls
Copy link

coveralls commented Jul 19, 2021

Coverage Status

Coverage increased (+0.03%) to 92.09% when pulling 42132f5 on DudeNr33:fix-4689-threadpoolexecutor into f437752 on PyCQA:main.

@DudeNr33 DudeNr33 marked this pull request as ready for review July 19, 2021 17:25
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.

Thank you for taking the time to fix the false positive for this checker and participating in the issue related to it, much appreciated ! I made some suggestion feel free to ignore if it's not relevant.

pylint/checkers/refactoring/refactoring_checker.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/refactoring_checker.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/refactoring_checker.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/refactoring_checker.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/refactoring_checker.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/refactoring_checker.py Outdated Show resolved Hide resolved
pylint/checkers/refactoring/refactoring_checker.py Outdated Show resolved Hide resolved
@DudeNr33
Copy link
Collaborator Author

Thanks for the review, I will implement the suggested changes (but only tomorrow).
Especially the __iter__ and a clear (or clear_all) method are nice improvements.

@Pierre-Sassoulas Pierre-Sassoulas merged commit dd54e55 into pylint-dev:main Jul 20, 2021
@Pierre-Sassoulas
Copy link
Member

Thanks for the fix ! This was the last MR for pylint 2.9.4 I'm going to release it now :)

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.

consider-using-with on ThreadPoolExecutor?
3 participants