Skip to content

Commit 56fe21e

Browse files
miss-islingtonNickCrewssirosenencukou
authored
[3.15] gh-95484: Improve tempfile docs for conditions when files are removed (GH-95485) (GH-163076)
(cherry picked from commit b40f5b9) Co-authored-by: Nick Crews <nicholas.b.crews@gmail.com> Co-authored-by: Stephen Rosen <sirosen@globus.org> Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 6ac4ebf commit 56fe21e

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
@@ -32,17 +32,19 @@ 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+
37+
The object can be used as a context manager
38+
(see :ref:`tempfile-examples`).
39+
Exiting the context manager closes the file.
40+
41+
Under Unix, the directory entry for the file is either not created at all or is
42+
removed immediately after the file is created. Other platforms do not support
3943
this; your code should not rely on a temporary file created using this
4044
function having or not having a visible name in the file system.
4145

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.
46+
The file will be removed from the file system when the object is closed
47+
(including an implicit close when the object is garbage collected).
4648

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

0 commit comments

Comments
 (0)