summaryrefslogtreecommitdiffstats
path: root/Lib/tempfile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-09-24 10:29:27 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-09-24 10:29:27 (GMT)
commite9a086bf010626d0e0af54693db776ccda76b5c4 (patch)
treeddf028fb988807e8c612681d7d608ac82a1f51ba /Lib/tempfile.py
parent43705d76aa39a9517ffa5fa124f9333a7874fbd9 (diff)
parent5e193ac0bd6bd4d4a122fd9aa2446ee70e5f2bf1 (diff)
downloadcpython-e9a086bf010626d0e0af54693db776ccda76b5c4.zip
cpython-e9a086bf010626d0e0af54693db776ccda76b5c4.tar.gz
cpython-e9a086bf010626d0e0af54693db776ccda76b5c4.tar.bz2
Issue #22427: TemporaryDirectory no longer attempts to clean up twice when
used in the with statement in generator.
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r--Lib/tempfile.py15
1 files changed, 3 insertions, 12 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index 5d9c719..d58d5dd 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -689,11 +689,6 @@ class TemporaryDirectory(object):
in it are removed.
"""
- # Handle mkdtemp raising an exception
- name = None
- _finalizer = None
- _closed = False
-
def __init__(self, suffix="", prefix=template, dir=None):
self.name = mkdtemp(suffix, prefix, dir)
self._finalizer = _weakref.finalize(
@@ -701,10 +696,9 @@ class TemporaryDirectory(object):
warn_message="Implicitly cleaning up {!r}".format(self))
@classmethod
- def _cleanup(cls, name, warn_message=None):
+ def _cleanup(cls, name, warn_message):
_shutil.rmtree(name)
- if warn_message is not None:
- _warnings.warn(warn_message, ResourceWarning)
+ _warnings.warn(warn_message, ResourceWarning)
def __repr__(self):
@@ -717,8 +711,5 @@ class TemporaryDirectory(object):
self.cleanup()
def cleanup(self):
- if self._finalizer is not None:
- self._finalizer.detach()
- if self.name is not None and not self._closed:
+ if self._finalizer.detach():
_shutil.rmtree(self.name)
- self._closed = True