Skip to content

Commit 0e1bf8e

Browse files
miss-islingtonNickCrewssirosenencukou
authored
[3.14] gh-95484: Improve tempfile docs for conditions when files are removed (GH-95485) (GH-163075)
(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 f477d9a commit 0e1bf8e

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

44-
The resulting object can be used as a :term:`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.
48+
The file will be removed from the file system when the object is closed
49+
(including an implicit close when the object is garbage collected).
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)