Skip to content

Commit 84d5ce7

Browse files
committed
gh-95484: Improve docs for when tempfiles removed
1 parent 8a0d9a6 commit 84d5ce7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Doc/library/tempfile.rst

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

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

44-
The resulting object can be used as a context manager (see
45-
:ref:`tempfile-examples`). On completion of the context or
46-
destruction of the file object the temporary file will be removed
47-
from the filesystem.
43+
The temporary file will be removed from the filesystem when the returned
44+
file-like object:
45+
46+
- is closed
47+
- or, is garbage collected (and is implicitly closed)
48+
- or, at the completion of the context if used as a context manager (see
49+
:ref:`tempfile-examples`)
4850

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

0 commit comments

Comments
 (0)