File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -107,13 +107,10 @@ def __init__(
107
107
):
108
108
super (TempDirectory , self ).__init__ ()
109
109
110
- if path is None and delete is None :
111
- # If we were not given an explicit directory, and we were not given
112
- # an explicit delete option, then we'll default to deleting unless
113
- # the tempdir_registry says otherwise.
110
+ # If we were given an explicit directory, resolve delete option now.
111
+ # Otherwise we wait until cleanup and see what tempdir_registry says.
112
+ if path is not None and delete is None :
114
113
delete = True
115
- if _tempdir_registry :
116
- delete = _tempdir_registry .get_delete (kind )
117
114
118
115
if path is None :
119
116
path = self ._create (kind )
@@ -145,7 +142,14 @@ def __enter__(self):
145
142
146
143
def __exit__ (self , exc , value , tb ):
147
144
# type: (Any, Any, Any) -> None
148
- if self .delete :
145
+ if self .delete is not None :
146
+ delete = self .delete
147
+ elif _tempdir_registry :
148
+ delete = _tempdir_registry .get_delete (self .kind )
149
+ else :
150
+ delete = True
151
+
152
+ if delete :
149
153
self .cleanup ()
150
154
151
155
def _create (self , kind ):
You can’t perform that action at this time.
0 commit comments