@@ -60,7 +60,7 @@ def __init__(self, path):
6060try :
6161 Path ('/invented/file/path' ).resolve (strict = True )
6262except TypeError :
63- from tempfile import gettempdir
63+ from tempfile import TemporaryDirectory
6464
6565 def _patch_resolve (self , strict = False ):
6666 """Add the argument strict to signature in Python>3,<3.6."""
@@ -80,15 +80,15 @@ def _write_text(self, text):
8080 Path .write_text = _write_text
8181
8282 try :
83- with tempfile . TemporaryDirectory () as tmpdir :
83+ with TemporaryDirectory () as tmpdir :
8484 (Path (tmpdir ) / 'exist_ok_test' ).mkdir (exist_ok = True )
8585 except TypeError :
8686 def _mkdir (self , mode = 0o777 , parents = False , exist_ok = False ):
87- if not exist_ok and self . exists () :
88- raise FileExistsError (str (self ))
89- if not parents and not Path ( str ( self . parents )) .exists ():
90- raise FileNotFoundError (str (self . parents ) )
91- os . makedirs ( str ( self ), mode = mode , exist_ok = exist_ok )
87+ if parents :
88+ os . makedirs (str (self ), mode = mode , exist_ok = exist_ok )
89+ elif not exist_ok or not self .exists ():
90+ os . mkdir (str (self ), mode = mode )
91+
9292 Path .mkdir = _mkdir
9393
9494except FileNotFoundError :
0 commit comments