From 62407c95c2e81ac38c0e130afe423b3bc4bde907 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Tue, 30 Jun 2026 03:44:01 +0000 Subject: [PATCH 01/16] Make tempfile.TemporaryFileWrapper public --- Doc/library/tempfile.rst | 36 ++++++++++++++++++++++++++++++++---- Lib/tempfile.py | 7 +++++-- Lib/test/test_tempfile.py | 16 +++++++++++++++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index bf9198e175a0e1..47a00bfd4b35ce 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -14,10 +14,11 @@ This module creates temporary files and directories. It works on all supported platforms. :class:`TemporaryFile`, :class:`NamedTemporaryFile`, -:class:`TemporaryDirectory`, and :class:`SpooledTemporaryFile` are high-level -interfaces which provide automatic cleanup and can be used as -:term:`context managers `. :func:`mkstemp` and -:func:`mkdtemp` are lower-level functions which require manual cleanup. +:class:`TemporaryFileWrapper`, :class:`TemporaryDirectory`, and +:class:`SpooledTemporaryFile` are high-level interfaces which provide +automatic cleanup and can be used as :term:`context managers +`. :func:`mkstemp` and :func:`mkdtemp` are lower-level +functions which require manual cleanup. All the user-callable functions and constructors take additional arguments which allow direct control over the location and name of temporary files and @@ -140,6 +141,33 @@ The module defines the following user-callable items: .. versionchanged:: 3.12 Added *delete_on_close* parameter. +.. class:: TemporaryFileWrapper(file, name, delete=True, delete_on_close=True) + + A mutable wrapper returned by :func:`NamedTemporaryFile`. It wraps the + underlying file object, delegating attribute access to it, and ensures + the temporary file is deleted when appropriate. + + .. attribute:: file + + The underlying :term:`file-like object`. + + .. attribute:: name + + The file name of the temporary file. + + .. method:: close() + + Close the temporary file, possibly deleting it depending on the + *delete* and *delete_on_close* arguments passed to + :func:`NamedTemporaryFile`. + + .. note:: + + ``tempfile._TemporaryFileWrapper`` is kept as a backwards compatible + alias for this class. + + .. versionadded:: 3.16 + .. class:: SpooledTemporaryFile(max_size=0, mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, *, errors=None) diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 6dac9ab3c41717..a938afae96c3e7 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -31,6 +31,7 @@ "TMP_MAX", "gettempprefix", # constants "tempdir", "gettempdir", "gettempprefixb", "gettempdirb", + "TemporaryFileWrapper", ] @@ -484,7 +485,7 @@ def __del__(self): _warnings.warn(self.warn_message, ResourceWarning) -class _TemporaryFileWrapper: +class TemporaryFileWrapper: """Temporary file wrapper This class provides a wrapper around files opened for @@ -555,6 +556,8 @@ def __iter__(self): for line in self.file: yield line +_TemporaryFileWrapper = TemporaryFileWrapper + def NamedTemporaryFile(mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, delete=True, *, errors=None, @@ -607,7 +610,7 @@ def opener(*args): raw = getattr(file, 'buffer', file) raw = getattr(raw, 'raw', raw) raw.name = name - return _TemporaryFileWrapper(file, name, delete, delete_on_close) + return TemporaryFileWrapper(file, name, delete, delete_on_close) except: file.close() raise diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 3b081ecd4a3aa5..7fe33bdaf3ba26 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -148,6 +148,7 @@ def test_exports(self): "template" : 1, "SpooledTemporaryFile" : 1, "TemporaryDirectory" : 1, + "TemporaryFileWrapper" : 1, } unexp = [] @@ -1141,7 +1142,7 @@ def my_func(dir): try: with self.assertWarnsRegex( expected_warning=ResourceWarning, - expected_regex=r"Implicitly cleaning up <_TemporaryFileWrapper file=.*>", + expected_regex=r"Implicitly cleaning up ", ): tmp_name = my_func(dir) support.gc_collect() @@ -1195,6 +1196,19 @@ def test_unexpected_error(self): # How to test the mode and bufsize parameters? +class TestTemporaryFileWrapper(BaseTestCase): + """Test TemporaryFileWrapper.""" + + def test_public_name(self): + self.assertIs(tempfile.TemporaryFileWrapper, tempfile._TemporaryFileWrapper) + + def test_in_all(self): + self.assertIn("TemporaryFileWrapper", tempfile.__all__) + + def test_is_return_type_of_named_temporary_file(self): + with tempfile.NamedTemporaryFile() as f: + self.assertIsInstance(f, tempfile.TemporaryFileWrapper) + class TestSpooledTemporaryFile(BaseTestCase): """Test SpooledTemporaryFile().""" From 4fcba6710fdc946c48ccaea50014108e376e8575 Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Wed, 1 Jul 2026 12:27:16 +0530 Subject: [PATCH 02/16] Update Doc/library/tempfile.rst Co-authored-by: sobolevn --- Doc/library/tempfile.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index 47a00bfd4b35ce..a17e1ec5219ebf 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -166,7 +166,7 @@ The module defines the following user-callable items: ``tempfile._TemporaryFileWrapper`` is kept as a backwards compatible alias for this class. - .. versionadded:: 3.16 + .. versionadded:: next .. class:: SpooledTemporaryFile(max_size=0, mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, *, errors=None) From 38db57fdc807811e8b028a869c6ba87d9edce28e Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Wed, 1 Jul 2026 22:50:33 +0000 Subject: [PATCH 03/16] add depreciation and update tests --- Lib/tempfile.py | 12 +++++++++++- Lib/test/test_tempfile.py | 27 +++++++++++++-------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Lib/tempfile.py b/Lib/tempfile.py index a938afae96c3e7..bb064611cb987a 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -556,7 +556,17 @@ def __iter__(self): for line in self.file: yield line -_TemporaryFileWrapper = TemporaryFileWrapper +# _TemporaryFileWrapper is deprecated in favor of the public +def __getattr__(name): + if name == "_TemporaryFileWrapper": + _warnings._deprecated( + "tempfile._TemporaryFileWrapper", + message="{name} is deprecated and will be removed in a future " + "version. Use tempfile.TemporaryFileWrapper instead.", + remove=(3, 16), + ) + return TemporaryFileWrapper + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") def NamedTemporaryFile(mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index 7fe33bdaf3ba26..c5f5bf000a3177 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -981,12 +981,23 @@ def do_create(self, dir=None, pre="", suf="", delete=True): def test_basic(self): # NamedTemporaryFile can create files - self.do_create() + f = self.do_create() + self.assertIsInstance(f, tempfile.TemporaryFileWrapper) self.do_create(pre="a") self.do_create(suf="b") self.do_create(pre="a", suf="b") self.do_create(pre="aa", suf=".txt") + def test_in_all(self): + self.assertIn("TemporaryFileWrapper", tempfile.__all__) + + def test_deprecated_TemporaryFileWrapper_alias(self): + # gh-152586: _TemporaryFileWrapper is a deprecated alias + # for the public TemporaryFileWrapper class. + with self.assertWarns(DeprecationWarning): + obj = tempfile._TemporaryFileWrapper + self.assertIs(obj, tempfile.TemporaryFileWrapper) + def test_method_lookup(self): # Issue #18879: Looking up a temporary file method should keep it # alive long enough. @@ -1186,7 +1197,7 @@ def test_bad_encoding(self): def test_unexpected_error(self): dir = tempfile.mkdtemp() self.addCleanup(os_helper.rmtree, dir) - with mock.patch('tempfile._TemporaryFileWrapper') as mock_ntf, \ + with mock.patch('tempfile.TemporaryFileWrapper') as mock_ntf, \ mock.patch('io.open', mock.mock_open()) as mock_open: mock_ntf.side_effect = KeyboardInterrupt() with self.assertRaises(KeyboardInterrupt): @@ -1196,18 +1207,6 @@ def test_unexpected_error(self): # How to test the mode and bufsize parameters? -class TestTemporaryFileWrapper(BaseTestCase): - """Test TemporaryFileWrapper.""" - - def test_public_name(self): - self.assertIs(tempfile.TemporaryFileWrapper, tempfile._TemporaryFileWrapper) - - def test_in_all(self): - self.assertIn("TemporaryFileWrapper", tempfile.__all__) - - def test_is_return_type_of_named_temporary_file(self): - with tempfile.NamedTemporaryFile() as f: - self.assertIsInstance(f, tempfile.TemporaryFileWrapper) class TestSpooledTemporaryFile(BaseTestCase): """Test SpooledTemporaryFile().""" From a790753b0894e9c94bd6d2dece6d3b7c69f6ff24 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Wed, 1 Jul 2026 22:59:28 +0000 Subject: [PATCH 04/16] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst diff --git a/Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst b/Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst new file mode 100644 index 00000000000000..94e0c3ccf56a2a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst @@ -0,0 +1 @@ +:class:`tempfile._TemporaryFileWrapper` has been renamed to the public :class:`tempfile.TemporaryFileWrapper`. The old private name is kept as a deprecated alias and will be removed in a future version. From c30d7a238dc2b5883912ca2193922c7a2f787f1a Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Wed, 1 Jul 2026 23:04:09 +0000 Subject: [PATCH 05/16] Make tempfile._TemporaryFileWrapper public as TemporaryFileWrapper --- Lib/test/test_urllib_response.py | 2 +- Lib/urllib/response.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_urllib_response.py b/Lib/test/test_urllib_response.py index d949fa38bfc42f..8c4acf4afc845e 100644 --- a/Lib/test/test_urllib_response.py +++ b/Lib/test/test_urllib_response.py @@ -21,7 +21,7 @@ def setUp(self): def test_with(self): addbase = urllib.response.addbase(self.fp) - self.assertIsInstance(addbase, tempfile._TemporaryFileWrapper) + self.assertIsInstance(addbase, tempfile.TemporaryFileWrapper) def f(): with addbase as spam: diff --git a/Lib/urllib/response.py b/Lib/urllib/response.py index 5a2c3cc78c395d..fc57ad82d99ac0 100644 --- a/Lib/urllib/response.py +++ b/Lib/urllib/response.py @@ -11,7 +11,7 @@ __all__ = ['addbase', 'addclosehook', 'addinfo', 'addinfourl'] -class addbase(tempfile._TemporaryFileWrapper): +class addbase(tempfile.TemporaryFileWrapper): """Base class for addinfo and addclosehook. Is a good idea for garbage collection.""" # XXX Add a method to expose the timeout on the underlying socket? From 0a2d25a0e669c8e3ad67f0f7ad0bcf0140d0b1fd Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Thu, 2 Jul 2026 11:55:18 +0530 Subject: [PATCH 06/16] Update Lib/tempfile.py Co-authored-by: sobolevn --- Lib/tempfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tempfile.py b/Lib/tempfile.py index bb064611cb987a..36a3fad2366770 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -563,7 +563,7 @@ def __getattr__(name): "tempfile._TemporaryFileWrapper", message="{name} is deprecated and will be removed in a future " "version. Use tempfile.TemporaryFileWrapper instead.", - remove=(3, 16), + remove=(3, 21), ) return TemporaryFileWrapper raise AttributeError(f"module {__name__!r} has no attribute {name!r}") From 4e67a019bc30d0b35c3c1c9d026ae901f1142a15 Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Thu, 2 Jul 2026 11:55:33 +0530 Subject: [PATCH 07/16] Update Lib/tempfile.py Co-authored-by: sobolevn --- Lib/tempfile.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 36a3fad2366770..b92d1319ab6d4a 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -561,7 +561,10 @@ def __getattr__(name): if name == "_TemporaryFileWrapper": _warnings._deprecated( "tempfile._TemporaryFileWrapper", - message="{name} is deprecated and will be removed in a future " + message=( + "{name!r} is deprecated and slated for removal in Python {remove}. " + "Use tempfile.TemporaryFileWrapper instead." + ) "version. Use tempfile.TemporaryFileWrapper instead.", remove=(3, 21), ) From 4d7826e80e4a285b6c42d812286ede1f31686dca Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Thu, 2 Jul 2026 11:55:45 +0530 Subject: [PATCH 08/16] Update Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst Co-authored-by: sobolevn --- .../next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst b/Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst index 94e0c3ccf56a2a..d357b61bb19f6e 100644 --- a/Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst +++ b/Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst @@ -1 +1 @@ -:class:`tempfile._TemporaryFileWrapper` has been renamed to the public :class:`tempfile.TemporaryFileWrapper`. The old private name is kept as a deprecated alias and will be removed in a future version. +:class:`tempfile._TemporaryFileWrapper` has been renamed to the public :class:`tempfile.TemporaryFileWrapper`. The old private name is kept as a deprecated alias and will be removed in Python 3.21. From da8b633810317e901965d70360c2b8c9c699a4dc Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Thu, 2 Jul 2026 07:24:06 +0000 Subject: [PATCH 09/16] update doc for depreciation --- Doc/deprecations/pending-removal-in-3.21.rst | 5 +++++ Doc/library/tempfile.rst | 4 ++++ Doc/whatsnew/3.16.rst | 7 +++++++ Lib/tempfile.py | 3 +-- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-3.21.rst b/Doc/deprecations/pending-removal-in-3.21.rst index 18b89a20e4a208..c62c1ba72fb3e1 100644 --- a/Doc/deprecations/pending-removal-in-3.21.rst +++ b/Doc/deprecations/pending-removal-in-3.21.rst @@ -17,3 +17,8 @@ Pending removal in Python 3.21 are not generated by the parser or accepted by the code generator. * The ``dims`` property of ``ast.Tuple`` will be removed in Python 3.21. Use the ``ast.Tuple.elts`` property instead. + +* :mod:`tempfile`: + + * ``tempfile._TemporaryFileWrapper`` will be removed. Use the public + :class:`tempfile.TemporaryFileWrapper` instead. diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index a17e1ec5219ebf..c90a243426939e 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -161,6 +161,10 @@ The module defines the following user-callable items: *delete* and *delete_on_close* arguments passed to :func:`NamedTemporaryFile`. + .. deprecated:: next + ``tempfile._TemporaryFileWrapper`` is kept as a deprecated alias + for this class and will be removed in Python 3.21. + .. note:: ``tempfile._TemporaryFileWrapper`` is kept as a backwards compatible diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index 7841fa56cc5952..1300b9c3823976 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -506,6 +506,13 @@ New deprecations 3.9, now issues a deprecation warning on use. This property is slated for removal in 3.21. Use ``ast.Tuple.elts`` instead. +* :mod:`tempfile` + + * The private ``tempfile._TemporaryFileWrapper`` name is deprecated. + Use the new public :class:`tempfile.TemporaryFileWrapper` instead, + which is the return type of :func:`tempfile.NamedTemporaryFile`. + It is slated for removal in Python 3.21. + .. Add deprecations above alphabetically, not here at the end. .. include:: ../deprecations/pending-removal-in-3.17.rst diff --git a/Lib/tempfile.py b/Lib/tempfile.py index b92d1319ab6d4a..1e6b4d2a554013 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -564,8 +564,7 @@ def __getattr__(name): message=( "{name!r} is deprecated and slated for removal in Python {remove}. " "Use tempfile.TemporaryFileWrapper instead." - ) - "version. Use tempfile.TemporaryFileWrapper instead.", + ), remove=(3, 21), ) return TemporaryFileWrapper From 88b8b4bc4b4c19aad29544d92d517e78e1b9e245 Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Thu, 2 Jul 2026 13:05:53 +0530 Subject: [PATCH 10/16] Update Doc/library/tempfile.rst Co-authored-by: sobolevn --- Doc/library/tempfile.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index c90a243426939e..a4f74e3dd58c8a 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -168,7 +168,8 @@ The module defines the following user-callable items: .. note:: ``tempfile._TemporaryFileWrapper`` is kept as a backwards compatible - alias for this class. + deprecated alias for this class. + It will be removed in Python 3.21 .. versionadded:: next From a63ce6d53fc7d2ba78d3332b8d91110092465d27 Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Thu, 2 Jul 2026 13:06:07 +0530 Subject: [PATCH 11/16] Update Lib/test/test_tempfile.py Co-authored-by: sobolevn --- Lib/test/test_tempfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py index c5f5bf000a3177..e33cc65e090e3b 100644 --- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -1207,7 +1207,6 @@ def test_unexpected_error(self): # How to test the mode and bufsize parameters? - class TestSpooledTemporaryFile(BaseTestCase): """Test SpooledTemporaryFile().""" From efc960f5580e0feb0fa559d152e8e070e75f0568 Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Thu, 2 Jul 2026 13:07:26 +0530 Subject: [PATCH 12/16] remove comment --- Lib/tempfile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 1e6b4d2a554013..485038417c65c6 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -556,7 +556,6 @@ def __iter__(self): for line in self.file: yield line -# _TemporaryFileWrapper is deprecated in favor of the public def __getattr__(name): if name == "_TemporaryFileWrapper": _warnings._deprecated( From 8f629572ea3953817b0ef39233aea9bd62596f46 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Thu, 2 Jul 2026 08:26:11 +0000 Subject: [PATCH 13/16] Document that NamedTemporaryFile returns TemporaryFileWrapper --- Doc/library/tempfile.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index a4f74e3dd58c8a..ec5c0a3d7dedc3 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -85,13 +85,13 @@ The module defines the following user-callable items: :func:`TemporaryFile` with *delete* and *delete_on_close* parameters that determine whether and how the named file should be automatically deleted. - The returned object is always a :term:`file-like object` whose :attr:`!file` - attribute is the underlying true file object. This file-like object - can be used in a :keyword:`with` statement, just like a normal file. The - name of the temporary file can be retrieved from the :attr:`!name` attribute - of the returned file-like object. On Unix, unlike with the - :func:`TemporaryFile`, the directory entry does not get unlinked immediately - after the file creation. + The returned object is always a :class:`TemporaryFileWrapper` instance + (a :term:`file-like object`) whose :attr:`!file` attribute is the underlying + true file object. This file-like object can be used in a :keyword:`with` + statement, just like a normal file. The name of the temporary file can be + retrieved from the :attr:`!name` attribute of the returned file-like object. + On Unix, unlike with the :func:`TemporaryFile`, the directory entry does not + get unlinked immediately after the file creation. If *delete* is true (the default) and *delete_on_close* is true (the default), the file is deleted as soon as it is closed. If *delete* is true From dd1b9a3cc214ff6a60a557a5367b1b537919923b Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Thu, 2 Jul 2026 14:13:46 +0530 Subject: [PATCH 14/16] Update Doc/library/tempfile.rst Co-authored-by: sobolevn --- Doc/library/tempfile.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index ec5c0a3d7dedc3..d9ceb5de9b5793 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -86,7 +86,7 @@ The module defines the following user-callable items: determine whether and how the named file should be automatically deleted. The returned object is always a :class:`TemporaryFileWrapper` instance - (a :term:`file-like object`) whose :attr:`!file` attribute is the underlying + (a :term:`file-like object`) whose :attr:`~TemporaryFileWrapper.file` attribute is the underlying true file object. This file-like object can be used in a :keyword:`with` statement, just like a normal file. The name of the temporary file can be retrieved from the :attr:`!name` attribute of the returned file-like object. From 375a717e7007b0f761ad68e1904a8c8dd7031082 Mon Sep 17 00:00:00 2001 From: Aniket <148300120+Aniketsy@users.noreply.github.com> Date: Thu, 2 Jul 2026 14:25:56 +0530 Subject: [PATCH 15/16] Update Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst Co-authored-by: sobolevn --- .../next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst b/Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst index d357b61bb19f6e..6c800551c906f2 100644 --- a/Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst +++ b/Misc/NEWS.d/next/Library/2026-07-01-22-59-25.gh-issue-152586.WuEae6.rst @@ -1 +1 @@ -:class:`tempfile._TemporaryFileWrapper` has been renamed to the public :class:`tempfile.TemporaryFileWrapper`. The old private name is kept as a deprecated alias and will be removed in Python 3.21. +:class:`!tempfile._TemporaryFileWrapper` has been renamed to the public :class:`tempfile.TemporaryFileWrapper`. The old private name is kept as a deprecated alias and will be removed in Python 3.21. From c91fad418298c2a9ddb7f469854e39b85371dba3 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 7 Jul 2026 23:58:43 +0300 Subject: [PATCH 16/16] Apply suggestions from code review Co-authored-by: sobolevn --- Doc/library/tempfile.rst | 4 ---- Doc/whatsnew/3.16.rst | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index d9ceb5de9b5793..8c387853d0417f 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -161,10 +161,6 @@ The module defines the following user-callable items: *delete* and *delete_on_close* arguments passed to :func:`NamedTemporaryFile`. - .. deprecated:: next - ``tempfile._TemporaryFileWrapper`` is kept as a deprecated alias - for this class and will be removed in Python 3.21. - .. note:: ``tempfile._TemporaryFileWrapper`` is kept as a backwards compatible diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index 504fbb204a70f8..9a956227dd4be7 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -559,10 +559,10 @@ New deprecations * :mod:`tempfile` - * The private ``tempfile._TemporaryFileWrapper`` name is deprecated. + * The private ``tempfile._TemporaryFileWrapper`` name is deprecated + and is slated for removal in Python 3.21. Use the new public :class:`tempfile.TemporaryFileWrapper` instead, which is the return type of :func:`tempfile.NamedTemporaryFile`. - It is slated for removal in Python 3.21. .. Add deprecations above alphabetically, not here at the end.