Skip to content

Commit eb61e19

Browse files
committed
gh-95484: Improve docs for when tempfiles removed
1 parent ba1e1c1 commit eb61e19

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Doc/library/tempfile.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,18 @@ The module defines the following user-callable items:
3232
.. function:: TemporaryFile(mode='w+b', buffering=-1, encoding=None, newline=None, suffix=None, prefix=None, dir=None, *, errors=None)
3333

3434
Return a :term:`file-like object` that can be used as a temporary storage area.
35-
The file is created securely, using the same rules as :func:`mkstemp`. It will be destroyed as soon
36-
as it is closed (including an implicit close when the object is garbage
37-
collected). Under Unix, the directory entry for the file is either not created at all or is removed
38-
immediately after the file is created. Other platforms do not support
35+
The file is created securely, using the same rules as :func:`mkstemp`.
36+
Under Unix, the directory entry for the file is either not created at all or is
37+
removed immediately after the file is created. Other platforms do not support
3938
this; your code should not rely on a temporary file created using this
4039
function having or not having a visible name in the file system.
4140

42-
The resulting object can be used as a :term:`context manager` (see
43-
:ref:`tempfile-examples`). On completion of the context or
44-
destruction of the file object the temporary file will be removed
45-
from the filesystem.
41+
The temporary file will be removed from the file system under the following conditions:
42+
43+
- It is closed.
44+
- or, it is garbage collected (and is implicitly closed)
45+
- or, at the completion of the context if used as a context manager (see
46+
:ref:`tempfile-examples`)
4647

4748
The *mode* parameter defaults to ``'w+b'`` so that the file created can
4849
be read and written without being closed. Binary mode is used so that it

0 commit comments

Comments
 (0)