]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-127381: pathlib ABCs: remove `WritablePath.mkdir()` arguments (#130611)
authorBarney Gale <barney.gale@gmail.com>
Sat, 1 Mar 2025 21:25:38 +0000 (21:25 +0000)
committerGitHub <noreply@github.com>
Sat, 1 Mar 2025 21:25:38 +0000 (21:25 +0000)
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.

Lib/pathlib/_abc.py
Lib/test/test_pathlib/test_pathlib_abc.py

index cb5af3230bfd67846a22d1284c66b3922e3482d6..d9fb018d75f538d4bc50d94a185e96cb01c243df 100644 (file)
@@ -352,7 +352,7 @@ class WritablePath(JoinablePath):
         raise NotImplementedError
 
     @abstractmethod
-    def mkdir(self, mode=0o777, parents=False, exist_ok=False):
+    def mkdir(self):
         """
         Create a new directory at this given path.
         """
index efc6c17962e2617cf63d9f11da6450863f33d110..1c1797ff04f653541462190b9f0e2bf78fb4d06f 100644 (file)
@@ -914,23 +914,17 @@ class DummyWritablePath(WritablePath, DummyJoinablePath):
         self._directories[parent].add(name)
         return DummyWritablePathIO(self._files, path)
 
-    def mkdir(self, mode=0o777, parents=False, exist_ok=False):
+    def mkdir(self):
         path = str(self)
         parent = str(self.parent)
         if path in self._directories:
-            if exist_ok:
-                return
-            else:
-                raise FileExistsError(errno.EEXIST, "File exists", path)
+            raise FileExistsError(errno.EEXIST, "File exists", path)
         try:
             if self.name:
                 self._directories[parent].add(self.name)
             self._directories[path] = set()
         except KeyError:
-            if not parents:
-                raise FileNotFoundError(errno.ENOENT, "File not found", parent) from None
-            self.parent.mkdir(parents=True, exist_ok=True)
-            self.mkdir(mode, parents=False, exist_ok=exist_ok)
+            raise FileNotFoundError(errno.ENOENT, "File not found", parent) from None
 
     def symlink_to(self, target, target_is_directory=False):
         raise NotImplementedError