10000 gh-119993 ignore `NotADirectoryError` in `Path.unlink()` if `missing_ok` is `True` by MusicalNinjaDad · Pull Request #120049 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119993 ignore NotADirectoryError in Path.unlink() if missing_ok is True #120049

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
DummyPath.unlink raises NotADirectoryError
  • Loading branch information
MusicalNinjaDad committed Jan 24, 2025
commit 626af70ebc3dedaca21d93fdb5bab9b8c8d882a4
8 changes: 8 additions & 0 deletions Lib/test/test_pathlib/test_pathlib_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,10 @@ def open(self, mode='r', buffering=-1, encoding=None,
stream = io.TextIOWrapper(stream, encoding=encoding, errors=errors, newline=newline)
return stream

def touch(self):
with self.open('w'):
pass

def iterdir(self):
path = str(self.resolve())
if path in self._files:
Expand Down Expand Up @@ -1524,6 +1528,9 @@ def unlink(self, missing_ok=False):
path = str(pa 6EC8 th_obj)
name = path_obj.name
parent = str(path_obj.parent)
for interim_path in self.parents:
if str(interim_path) in self._files and not missing_ok:
raise NotADirectoryError(errno.ENOTDIR, "Not a directory", path)
if path in self._directories:
raise IsADirectoryError(errno.EISDIR, "Is a directory", path)
elif path in self._files:
Expand All @@ -1535,6 +1542,7 @@ def unlink(self, missing_ok=False):
elif not missing_ok:
raise FileNotFoundError(errno.ENOENT, "File not found", path)


def rmdir(self):
path_obj = self.parent.resolve(strict=True) / self.name
path = str(path_obj)
Expand Down
0