@@ -149,7 +149,7 @@ def delete(filename: PathLike, **kwargs):
149
149
os .remove (os .path .join (os .getcwd (), filename ), ** kwargs )
150
150
151
151
152
- def maybe_make (directory : PathLike , mode : int = 0o777 , parents : bool = False , exist_ok : bool = False ):
152
+ def maybe_make (directory : PathLike , mode : int = 0o777 , parents : bool = False ):
153
153
"""
154
154
Create a directory at the given path, but only if the directory does not already exist.
155
155
@@ -164,18 +164,18 @@ def maybe_make(directory: PathLike, mode: int = 0o777, parents: bool = False, ex
164
164
If :py:obj:`True`, any missing parents of this path are created as needed; they are created with the
165
165
default permissions without taking mode into account (mimicking the POSIX mkdir -p command).
166
166
:no-default parents:
167
- :param exist_ok: If :py:obj:`False` (the default), a :class:`FileExistsError` is raised if the
168
- target directory already exists. If :py:obj:`True`, :class:`FileExistsError` exceptions
169
- will be ignored (same behavior as the POSIX mkdir -p command), but only if the last path
170
- component is not an existing non-directory file.
171
- :no-default exist_ok:
167
+
168
+ .. versionchanged:: 1.6.0 Removed the ``'exist_ok'`` option, since it made no sense in this context.
169
+
172
170
"""
173
171
174
172
if not isinstance (directory , pathlib .Path ):
175
173
directory = pathlib .Path (directory )
176
174
177
- if not directory .exists ():
178
- directory .mkdir (mode , parents , exist_ok )
175
+ try :
176
+ directory .mkdir (mode , parents , exist_ok = True )
177
+ except FileExistsError :
178
+ pass
179
179
180
180
181
181
def parent_path (path : PathLike ) -> pathlib .Path :
@@ -365,7 +365,6 @@ def maybe_make(
365
365
self ,
366
366
mode : int = 0o777 ,
367
367
parents : bool = False ,
368
- exist_ok : bool = False ,
369
368
):
370
369
"""
371
370
Create a directory at this path, but only if the directory does not already exist.
@@ -380,18 +379,18 @@ def maybe_make(
380
379
If :py:obj:`True`, any missing parents of this path are created as needed; they are created with the
381
380
default permissions without taking mode into account (mimicking the POSIX mkdir -p command).
382
381
:no-default parents:
383
- :param exist_ok: If :py:obj:`False` (the default), a :class:`FileExistsError` is raised if the
384
- target directory already exists. If :py:obj:`True`, :class:`FileExistsError` exceptions
385
- will be ignored (same behavior as the POSIX mkdir -p command), but only if the last path
386
- component is not an existing non-directory file.
387
- :no-default exist_ok:
388
382
389
383
:rtype:
390
384
391
385
.. versionadded:: 0.3.8
386
+
387
+ .. versionchanged:: 1.6.0 Removed the ``'exist_ok'`` option, since it made no sense in this context.
392
388
"""
393
389
394
- maybe_make (self , mode = mode , parents = parents , exist_ok = exist_ok )
390
+ try :
391
+ self .mkdir (mode , parents , exist_ok = True )
392
+ except FileExistsError :
393
+ pass
395
394
396
395
def append_text (
397
396
self ,
0 commit comments