bpo-41395: Register a cleanup function to close files for FileType objects in argparse #32257
+11
−1
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.
BPO-41395
make patchcheckHello! 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
ResourceWarningissue directly inargparseitself. 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 afile.closecleanup function withatexitfor files opened withFileTypeobjects, to ensure they are always closed.Previously:
With Patch:
https://bugs.python.org/issue41395