Skip to content

Commit b40f5b9

Browse files
NickCrewssirosenencukou
authored
gh-95484: Improve tempfile docs for conditions when files are removed (GH-95485)
Co-authored-by: Stephen Rosen <sirosen@globus.org> Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 79e357a commit b40f5b9

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎Doc/library/tempfile.rst‎

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

3535
Return a :term:`file-like object` that can be used as a temporary storage area.
36-
The file is created securely, using the same rules as :func:`mkstemp`. It will be destroyed as soon
37-
as it is closed (including an implicit close when the object is garbage
38-
collected). Under Unix, the directory entry for the file is either not created at all or is removed
39-
immediately after the file is created. Other platforms do not support
36+
The file is created securely, using the same rules as :func:`mkstemp`.
37+
38+
The object can be used as a context manager
39+
(see :ref:`tempfile-examples`).
40+
Exiting the context manager closes the file.
41+
42+
Under Unix, the directory entry for the file is either not created at all or is
43+
removed immediately after the file is created. Other platforms do not support
4044
this; your code should not rely on a temporary file created using this
4145
function having or not having a visible name in the file system.
4246

43-
The resulting object can be used as a :term:`context manager` (see
44-
:ref:`tempfile-examples`). On completion of the context or
45-
destruction of the file object the temporary file will be removed
46-
from the filesystem.
47+
The file will be removed from the file system when the object is closed
48+
(including an implicit close when the object is garbage collected).
4749

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

0 commit comments

Comments
 (0)