Skip to content

Commit c9932a9

Browse files
authored
GH-127381: pathlib ABCs: remove WritablePath.mkdir() arguments (#130611)
Remove the *mode*, *parents* and *exist_ok* arguments from `WritablePath.mkdir()`. These arguments imply support for POSIX permissions and checking for preexistence of the path or its parents, but subclasses of `WritablePath` may not have these capabilities. The public `Path.mkdir()` method retains these arguments.
1 parent a55dffd commit c9932a9

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

Lib/pathlib/_abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def symlink_to(self, target, target_is_directory=False):
352352
raise NotImplementedError
353353

354354
@abstractmethod
355-
def mkdir(self, mode=0o777, parents=False, exist_ok=False):
355+
def mkdir(self):
356356
"""
357357
Create a new directory at this given path.
358358
"""

Lib/test/test_pathlib/test_pathlib_abc.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -914,23 +914,17 @@ def __open_wb__(self, buffering=-1):
914914
self._directories[parent].add(name)
915915
return DummyWritablePathIO(self._files, path)
916916

917-
def mkdir(self, mode=0o777, parents=False, exist_ok=False):
917+
def mkdir(self):
918918
path = str(self)
919919
parent = str(self.parent)
920920
if path in self._directories:
921-
if exist_ok:
922-
return
923-
else:
924-
raise FileExistsError(errno.EEXIST, "File exists", path)
921+
raise FileExistsError(errno.EEXIST, "File exists", path)
925922
try:
926923
if self.name:
927924
self._directories[parent].add(self.name)
928925
self._directories[path] = set()
929926
except KeyError:
930-
if not parents:
931-
raise FileNotFoundError(errno.ENOENT, "File not found", parent) from None
932-
self.parent.mkdir(parents=True, exist_ok=True)
933-
self.mkdir(mode, parents=False, exist_ok=exist_ok)
927+
raise FileNotFoundError(errno.ENOENT, "File not found", parent) from None
934928

935929
def symlink_to(self, target, target_is_directory=False):
936930
raise NotImplementedError

0 commit comments

Comments
 (0)