Revert "gh-85567: Register a cleanup function to close files for FileType objects in argparse (#32257)" (#91771)
This reverts commit 328dbc051f84bd5fdf61101bb4fa61d85f8b7feb.
This commit is contained in:
parent
4e52c66f69
commit
c77953b23e
@ -84,7 +84,7 @@ __all__ = [
|
|||||||
'ZERO_OR_MORE',
|
'ZERO_OR_MORE',
|
||||||
]
|
]
|
||||||
|
|
||||||
import atexit as _atexit
|
|
||||||
import os as _os
|
import os as _os
|
||||||
import re as _re
|
import re as _re
|
||||||
import sys as _sys
|
import sys as _sys
|
||||||
@ -1268,12 +1268,8 @@ class FileType(object):
|
|||||||
|
|
||||||
# all other arguments are used as file names
|
# all other arguments are used as file names
|
||||||
try:
|
try:
|
||||||
fh = open(string, self._mode, self._bufsize, self._encoding, self._errors)
|
return open(string, self._mode, self._bufsize, self._encoding,
|
||||||
|
self._errors)
|
||||||
# Register cleanup function to close file
|
|
||||||
_atexit.register(fh.close)
|
|
||||||
|
|
||||||
return fh
|
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
args = {'filename': string, 'error': e}
|
args = {'filename': string, 'error': e}
|
||||||
message = _("can't open '%(filename)s': %(error)s")
|
message = _("can't open '%(filename)s': %(error)s")
|
||||||
|
@ -313,7 +313,6 @@ Nicolas Chauvat
|
|||||||
Jerry Chen
|
Jerry Chen
|
||||||
Michael Chermside
|
Michael Chermside
|
||||||
Ingrid Cheung
|
Ingrid Cheung
|
||||||
Adam Chhina
|
|
||||||
Terry Chia
|
Terry Chia
|
||||||
Albert Chin-A-Young
|
Albert Chin-A-Young
|
||||||
Adal Chiriliuc
|
Adal Chiriliuc
|
||||||
|
@ -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.
|
|
Loading…
x
Reference in New Issue
Block a user