FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-85567: Register a cleanup function to close files for FileType objects in argparse by achhina · Pull Request #32257 · python/cpython · GitHub

/ cpython Public

gh-85567: Register a cleanup function to close files for FileType objects in argparse - #32257

Merged
facundobatista merged 2 commits into
python:mainfrom
achhina:fix-issue-41395
Apr 18, 2022
Merged

gh-85567: Register a cleanup function to close files for FileType objects in argparse#32257
facundobatista merged 2 commits into
python:mainfrom
achhina:fix-issue-41395

Conversation

achhina commented Apr 2, 2022
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

BPO-41395

  • Signed CLA
  • Ran tests and make patchcheck
  • Added News Entry

Hello! First-time contribution, I've read through what I believe to be the relevant sections in the Python Developer's Guide, however, feel free to let me know if there is something I missed.

This is a follow-up to PR-21702, where it was suggested to address the ResourceWarning issue directly in argparse itself. However, as that was discussed back in 2020, I've attempted to take a stab at it myself! After reading a suggestion from @facundobatista, I have added a file.close cleanup function with atexit for files opened with FileType objects, to ensure they are always closed.

Previously:

❯ ./python.exe -Wall -m pickle p1              
{'a': 1}
sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='p1'>

❯ ./python.exe -Wall -m pickle p1 p2
/user: ResourceWarning: unclosed file <_io.BufferedReader name='p1'>
  value = [self._get_value(action, v) for v in arg_strings]
ResourceWarning: Enable tracemalloc to get the object allocation traceback
usage: pickle.py [-h] [-t] [-v] [pickle_file ...]
pickle.py: error: argument pickle_file: can't open 'p2': [Errno 2] No such file or directory: 'p2'

With Patch:

❯ ./python.exe -Wall -m pickle p1   
{'a': 1}

❯ ./python.exe -Wall -m pickle p1 p2
usage: pickle.py [-h] [-t] [-v] [pickle_file ...]
pickle.py: error: argument pickle_file: can't open 'p2': [Errno 2] No such file or directory: 'p2'

https://bugs.python.org/issue41395

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@achhina

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

achhina commented Apr 2, 2022
edited
Loading

Copy link
Copy Markdown
Contributor Author

CLA Missing

Our records indicate the following people have not signed the CLA:

@achhina

If you have recently signed the CLA, please wait at least one business day
before our records are updated

I had signed the CLA last night, so just waiting for it to be processed.

achhina commented Apr 12, 2022

Copy link
Copy Markdown
Contributor Author

Hi @facundobatista @serhiy-storchaka,

As both of you had reviewed PR-21702 and this follows up on that, would you be available to review this?

facundobatista left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hello! Thanks for the work! I annotated a couple of small suggestions.

Comment thread Lib/argparse.py Outdated
Comment thread Lib/argparse.py Outdated

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

ghost commented Apr 14, 2022
edited by ghost
Loading

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

achhina commented Apr 14, 2022

Copy link
Copy Markdown
Contributor Author

Thanks for taking a look @facundobatista!

I have made the requested changes; please review again

Copy link
Copy Markdown

Thanks for making the requested changes!

@facundobatista: please review the changes made to this pull request.

achhina changed the title bpo-41395: Register a cleanup function to close files for FileType objects in argparse gh-85567: Register a cleanup function to close files for FileType objects in argparse Apr 14, 2022

facundobatista left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It looks great! Thanks!

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL