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.
This commit is contained in:
Barney Gale 2025-03-01 21:25:38 +00:00 committed by GitHub
parent a55dffd66d
commit c9932a9ec8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 10 deletions

View file

@ -352,7 +352,7 @@ class WritablePath(JoinablePath):
raise NotImplementedError raise NotImplementedError
@abstractmethod @abstractmethod
def mkdir(self, mode=0o777, parents=False, exist_ok=False): def mkdir(self):
""" """
Create a new directory at this given path. Create a new directory at this given path.
""" """

View file

@ -914,23 +914,17 @@ class DummyWritablePath(WritablePath, DummyJoinablePath):
self._directories[parent].add(name) self._directories[parent].add(name)
return DummyWritablePathIO(self._files, path) return DummyWritablePathIO(self._files, path)
def mkdir(self, mode=0o777, parents=False, exist_ok=False): def mkdir(self):
path = str(self) path = str(self)
parent = str(self.parent) parent = str(self.parent)
if path in self._directories: if path in self._directories:
if exist_ok: raise FileExistsError(errno.EEXIST, "File exists", path)
return
else:
raise FileExistsError(errno.EEXIST, "File exists", path)
try: try:
if self.name: if self.name:
self._directories[parent].add(self.name) self._directories[parent].add(self.name)
self._directories[path] = set() self._directories[path] = set()
except KeyError: except KeyError:
if not parents: raise FileNotFoundError(errno.ENOENT, "File not found", parent) from None
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)
def symlink_to(self, target, target_is_directory=False): def symlink_to(self, target, target_is_directory=False):
raise NotImplementedError raise NotImplementedError