[issue25024] Allow passing "delete=False" to TemporaryDirectory

Maksim Beliaev report at bugs.python.org
Tue Nov 2 06:35:39 EDT 2021


Maksim Beliaev <maxbel15 at ya.ru> added the comment:

just want to correct code that Nils post in the last comment to really take args and kwargs

~~~
def mkdtemp_persistent(*args, persistent=True, **kwargs):
    if persistent:
        @contextmanager
        def normal_mkdtemp():
            yield tempfile.mkdtemp(*args, **kwargs)
        return normal_mkdtemp()
    else:
        return tempfile.TemporaryDirectory(*args, **kwargs)

with mkdtemp_persistent(persistent=False) as dir:
    ...
~~~

----------
nosy: +beliaev-maksim

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue25024>
_______________________________________


More information about the Python-bugs-list mailing list