diff options
author | Victor Stinner <vstinner@python.org> | 2022-04-21 01:10:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-21 01:10:51 (GMT) |
commit | c77953b23e4b864129edf7983eaa6a0d22414ec6 (patch) | |
tree | 963498bc5b7873bef8d5531573f3aa5bec184bc4 | |
parent | 4e52c66f6940a63ef7a62faf8ce32a980ac5aa2c (diff) | |
download | cpython-c77953b23e4b864129edf7983eaa6a0d22414ec6.zip cpython-c77953b23e4b864129edf7983eaa6a0d22414ec6.tar.gz cpython-c77953b23e4b864129edf7983eaa6a0d22414ec6.tar.bz2 |
Revert "gh-85567: Register a cleanup function to close files for FileType objects in argparse (#32257)" (#91771)
This reverts commit 328dbc051f84bd5fdf61101bb4fa61d85f8b7feb.
-rw-r--r-- | Lib/argparse.py | 10 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2022-04-02-14-40-53.bpo-41395.Y1ZVvT.rst | 3 |
3 files changed, 3 insertions, 11 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py index 881dfda..429a72a 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -84,7 +84,7 @@ __all__ = [ 'ZERO_OR_MORE', ] -import atexit as _atexit + import os as _os import re as _re import sys as _sys @@ -1268,12 +1268,8 @@ class FileType(object): # all other arguments are used as file names try: - fh = open(string, self._mode, self._bufsize, self._encoding, self._errors) - - # Register cleanup function to close file - _atexit.register(fh.close) - - return fh + return open(string, self._mode, self._bufsize, self._encoding, + self._errors) except OSError as e: args = {'filename': string, 'error': e} message = _("can't open '%(filename)s': %(error)s") @@ -313,7 +313,6 @@ Nicolas Chauvat Jerry Chen Michael Chermside Ingrid Cheung -Adam Chhina Terry Chia Albert Chin-A-Young Adal Chiriliuc diff --git a/Misc/NEWS.d/next/Library/2022-04-02-14-40-53.bpo-41395.Y1ZVvT.rst b/Misc/NEWS.d/next/Library/2022-04-02-14-40-53.bpo-41395.Y1ZVvT.rst deleted file mode 100644 index 5358b0e..0000000 --- a/Misc/NEWS.d/next/Library/2022-04-02-14-40-53.bpo-41395.Y1ZVvT.rst +++ /dev/null @@ -1,3 +0,0 @@ -FileType objects from argparse may not be closed and lead to -ResourceWarning. Register a file.close function with atexit for FileType -objects to ensure they are closed. Patch Contributed by Adam Chhina. |