Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GH-127381: pathlib ABCs: remove WritablePath.mkdir() arguments #130611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def symlink_to(self, target, target_is_directory=False):
raise NotImplementedError

@abstractmethod
def mkdir(self, mode=0o777, parents=False, exist_ok=False):
def mkdir(self):
"""
Create a new directory at this given path.
"""
Expand Down
12 changes: 3 additions & 9 deletions Lib/test/test_pathlib/test_pathlib_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,23 +914,17 @@ def __open_wb__(self, buffering=-1):
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
Expand Down
Loading