]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Revert "gh-85567: Register a cleanup function to close files for FileType objects...
authorVictor Stinner <vstinner@python.org>
Thu, 21 Apr 2022 01:10:51 +0000 (03:10 +0200)
committerGitHub <noreply@github.com>
Thu, 21 Apr 2022 01:10:51 +0000 (03:10 +0200)
This reverts commit 328dbc051f84bd5fdf61101bb4fa61d85f8b7feb.

Lib/argparse.py
Misc/ACKS
Misc/NEWS.d/next/Library/2022-04-02-14-40-53.bpo-41395.Y1ZVvT.rst [deleted file]

index 881dfda6d4d93210de82d9e3c86887d18e2b432f..429a72ab7841e787438286304bff6a084e351b64 100644 (file)
@@ -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")
index a1df84c0d6779ed7b9beed907de1416d50461bb9..5e66a2e757adf674c9021151de914cb7d869f7fd 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -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 (file)
index 5358b0e..0000000
+++ /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.