Skip to content

Commit

Permalink
Add DirEntry.is_file()
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Dec 3, 2024
1 parent 59201c3 commit 2fa207c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions Lib/pathlib/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DirEntry(Protocol):
"""

name: str
def is_file(self, *, follow_symlinks: bool = True) -> bool: ...
def is_dir(self, *, follow_symlinks: bool = True) -> bool: ...
def is_symlink(self) -> bool: ...

Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_pathlib/test_pathlib_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,8 +1387,11 @@ def __init__(self, name, is_symlink, is_dir):
def is_symlink(self):
return self._is_symlink

def is_file(self, *, follow_symlinks=True):
return (follow_symlinks or not self._is_symlink) and not self._is_dir

def is_dir(self, *, follow_symlinks=True):
return self._is_dir and (follow_symlinks or not self._is_symlink)
return (follow_symlinks or not self._is_symlink) and self._is_dir


class DummyPath(PathBase):
Expand Down

0 comments on commit 2fa207c

Please sign in to comment.