diff options
author | JakobDev <jakobdev@gmx.de> | 2023-03-24 21:52:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-24 21:52:06 (GMT) |
commit | 64cb1a4f0f0bc733a33ad7a6520e749ca1cdd43f (patch) | |
tree | 8565787413edcbc7a0475d7f67726b1938507c56 /Doc | |
parent | ded9a7fc194a1d5c0e38f475a45f8f77dbe9c6bc (diff) | |
download | cpython-64cb1a4f0f0bc733a33ad7a6520e749ca1cdd43f.zip cpython-64cb1a4f0f0bc733a33ad7a6520e749ca1cdd43f.tar.gz cpython-64cb1a4f0f0bc733a33ad7a6520e749ca1cdd43f.tar.bz2 |
gh-100131: Add optional delete parameter to tempfile.TemporaryDirectory() (#100132)
Add optional delete parameter to tempfile.TemporaryDirectory().
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/tempfile.rst | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index b6d4f5d..61358eb 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -173,7 +173,7 @@ The module defines the following user-callable items: or text *mode* was specified). -.. class:: TemporaryDirectory(suffix=None, prefix=None, dir=None, ignore_cleanup_errors=False) +.. class:: TemporaryDirectory(suffix=None, prefix=None, dir=None, ignore_cleanup_errors=False, *, delete=True) This class securely creates a temporary directory using the same rules as :func:`mkdtemp`. The resulting object can be used as a context manager (see @@ -195,6 +195,12 @@ The module defines the following user-callable items: (the :func:`cleanup` call, exiting the context manager, when the object is garbage-collected or during interpreter shutdown). + The *delete* parameter can be used to disable cleanup of the directory tree + upon exiting the context. While it may seem unusual for a context manager + to disable the action taken when exiting the context, it can be useful during + debugging or when you need your cleanup behavior to be conditional based on + other logic. + .. audit-event:: tempfile.mkdtemp fullpath tempfile.TemporaryDirectory .. versionadded:: 3.2 @@ -202,6 +208,9 @@ The module defines the following user-callable items: .. versionchanged:: 3.10 Added *ignore_cleanup_errors* parameter. + .. versionchanged:: 3.12 + Added the *delete* parameter. + .. function:: mkstemp(suffix=None, prefix=None, dir=None, text=False) |