From eb61e193d4f17cf8e8f06fdd9e3d28e774708dd6 Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Sat, 11 Apr 2026 09:16:37 -0800 Subject: [PATCH 1/3] pythongh-95484: Improve docs for when tempfiles removed --- Doc/library/tempfile.rst | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index bf9198e175a0e1..73cb6fe4a1220e 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -32,17 +32,18 @@ The module defines the following user-callable items: .. function:: TemporaryFile(mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, *, errors=None) Return a :term:`file-like object` that can be used as a temporary storage area. - The file is created securely, using the same rules as :func:`mkstemp`. It will be destroyed as soon - as it is closed (including an implicit close when the object is garbage - collected). Under Unix, the directory entry for the file is either not created at all or is removed - immediately after the file is created. Other platforms do not support + The file is created securely, using the same rules as :func:`mkstemp`. + Under Unix, the directory entry for the file is either not created at all or is + removed immediately after the file is created. Other platforms do not support this; your code should not rely on a temporary file created using this function having or not having a visible name in the file system. - The resulting object can be used as a :term:`context manager` (see - :ref:`tempfile-examples`). On completion of the context or - destruction of the file object the temporary file will be removed - from the filesystem. + The temporary file will be removed from the file system under the following conditions: + + - It is closed. + - or, it is garbage collected (and is implicitly closed) + - or, at the completion of the context if used as a context manager (see + :ref:`tempfile-examples`) The *mode* parameter defaults to ``'w+b'`` so that the file created can be read and written without being closed. Binary mode is used so that it From 87120b91c0d80777ad5da171e18abde3e86c3c60 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Mon, 16 Nov 2026 17:36:27 -0600 Subject: [PATCH 2/3] Apply review feedback --- 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 73cb6fe4a1220e..b95dd6d2e2e83e 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -32,18 +32,18 @@ The module defines the following user-callable items: .. function:: TemporaryFile(mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, *, errors=None) Return a :term:`file-like object` that can be used as a temporary storage area. - The file is created securely, using the same rules as :func:`mkstemp`. + The file is created securely, using the same rules as :func:`mkstemp`, + and the object can be used as a context manager + (see :ref:`tempfile-examples`). + Under Unix, the directory entry for the file is either not created at all or is removed immediately after the file is created. Other platforms do not support this; your code should not rely on a temporary file created using this function having or not having a visible name in the file system. - The temporary file will be removed from the file system under the following conditions: - - - It is closed. - - or, it is garbage collected (and is implicitly closed) - - or, at the completion of the context if used as a context manager (see - :ref:`tempfile-examples`) + The file will be removed from the file system when the object is closed or + garbage collected (and implicitly closed). Exiting the context manager + closes the file. The *mode* parameter defaults to ``'w+b'`` so that the file created can be read and written without being closed. Binary mode is used so that it From 7daf7fde46ede6aa10023e7195c106755105d181 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Wed, 2 Dec 2026 16:24:47 -0600 Subject: [PATCH 3/3] Apply batched suggestions from code review Co-authored-by: Petr Viktorin --- Doc/library/tempfile.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index a6fed8c6bc7082..e6443969d2f324 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -33,18 +33,19 @@ The module defines the following user-callable items: .. function:: TemporaryFile(mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, *, errors=None) Return a :term:`file-like object` that can be used as a temporary storage area. - The file is created securely, using the same rules as :func:`mkstemp`, - and the object can be used as a context manager + The file is created securely, using the same rules as :func:`mkstemp`. + + The object can be used as a context manager (see :ref:`tempfile-examples`). + Exiting the context manager closes the file. Under Unix, the directory entry for the file is either not created at all or is removed immediately after the file is created. Other platforms do not support this; your code should not rely on a temporary file created using this function having or not having a visible name in the file system. - The file will be removed from the file system when the object is closed or - garbage collected (and implicitly closed). Exiting the context manager - closes the file. + The file will be removed from the file system when the object is closed + (including an implicit close when the object is garbage collected). The *mode* parameter defaults to ``'w+b'`` so that the file created can be read and written without being closed. Binary mode is used so that it