Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6046a27
GH-125413: pathlib ABCs: replace `_scandir()` with `_info`
barneygale Dec 7, 2024
a57c4a8
Merge branch 'main' into gh-125413-info
barneygale Dec 9, 2024
76ef028
Rename `_info` to `_status`
barneygale Dec 9, 2024
5d92785
Add `Status` protocol.
barneygale Dec 9, 2024
dc403c6
Make `Path.status` public.
barneygale Dec 9, 2024
5a128b9
Fix docs typos
barneygale Dec 9, 2024
cac77a6
Docs fixes
barneygale Dec 9, 2024
6e09ada
Fix whatsnew
barneygale Dec 9, 2024
1d8713e
Fix _PathStatus repr, exception handling
barneygale Dec 9, 2024
f8ffbbd
Docs improvements
barneygale Dec 9, 2024
0a86e68
Move PathGlobber into glob.py, now that it uses the public path inter…
barneygale Dec 9, 2024
b0b621d
Simplify _PathStatus implementation a little
barneygale Dec 10, 2024
ef650fd
Add some tests
barneygale Dec 10, 2024
7b990c6
Add news
barneygale Dec 10, 2024
cf1073c
Docs tweaks
barneygale Dec 10, 2024
28bcf00
Merge branch 'main' into gh-125413-info
barneygale Dec 11, 2024
764b8ae
Wrap `os.DirEntry` in `_DirEntryStatus`
barneygale Dec 11, 2024
fa8931b
Add `Status.exists()`
barneygale Dec 11, 2024
2bb6221
Fix test name
barneygale Dec 11, 2024
923542b
Use status.exists() in docs example
barneygale Dec 11, 2024
68377c4
Docs editing
barneygale Dec 12, 2024
4f3f434
Few more test cases
barneygale Dec 12, 2024
2f4da5d
Merge branch 'main' into gh-125413-info
barneygale Dec 12, 2024
a7cffe7
Merge branch 'main' into gh-125413-info
barneygale Dec 12, 2024
dc6edc8
Merge branch 'main' into gh-125413-info
barneygale Dec 12, 2024
530771d
Suppress OSErrors
barneygale Dec 17, 2024
89ff6d4
Add Windows implementation using os.path.isdir() etc
barneygale Dec 17, 2024
592603b
Docstrings
barneygale Dec 17, 2024
bd6332a
Optimise Windows implementation a bit
barneygale Dec 17, 2024
f0ee0e9
More tidying of _PathStatus and friends
barneygale Dec 17, 2024
5ae8b06
`status` --> `info`
barneygale Dec 21, 2024
6e25d2d
`Parser` --> `_PathParser`
barneygale Dec 21, 2024
c93237d
Merge branch 'main' into gh-125413-info
barneygale Dec 22, 2024
2624363
Merge branch 'main' into gh-125413-info
barneygale Dec 29, 2024
662fd2d
Merge branch 'main' into gh-125413-info
barneygale Jan 5, 2025
dbc312c
Merge branch 'main' into gh-125413-info
barneygale Jan 8, 2025
ee7da1d
Update Lib/pathlib/_local.py
barneygale Jan 10, 2025
47ed3de
Merge branch 'main' into gh-125413-info
barneygale Jan 11, 2025
d2e254a
Move path info from `pathlib._local` to `pathlib._os`.
barneygale Jan 20, 2025
60b3ac4
Merge branch 'main' into gh-125413-info
barneygale Jan 21, 2025
7658dc8
Merge branch 'main' into gh-125413-info
barneygale Jan 21, 2025
c53c357
Merge branch 'main' into gh-125413-info
barneygale Jan 28, 2025
dad80ce
Merge branch 'main' into gh-125413-info
barneygale Feb 4, 2025
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
Docstrings
  • Loading branch information
barneygale committed Dec 17, 2024
commit 592603bc4421605fed8f455b4c58881dbc5c47d3
40 changes: 15 additions & 25 deletions Lib/pathlib/_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ def __repr__(self):


class _WindowsPathStatus(_PathStatusBase):
"""Implementation of pathlib.types.Status that provides file status
information for Windows paths. Don't try to construct it yourself."""
__slots__ = ('_exists', '_is_dir', '_is_file', '_is_symlink')

def exists(self, *, follow_symlinks=True):
"""Whether this path exists."""
if not follow_symlinks and self.is_symlink():
return True
try:
Expand All @@ -93,6 +96,7 @@ def exists(self, *, follow_symlinks=True):
return self._exists

def is_dir(self, *, follow_symlinks=True):
"""Whether this path is a directory."""
if not follow_symlinks and self.is_symlink():
return False
try:
Expand All @@ -102,6 +106,7 @@ def is_dir(self, *, follow_symlinks=True):
return self._is_dir

def is_file(self, *, follow_symlinks=True):
"""Whether this path is a regular file."""
if not follow_symlinks and self.is_symlink():
return False
try:
Expand All @@ -111,6 +116,7 @@ def is_file(self, *, follow_symlinks=True):
return self._is_file

def is_symlink(self):
"""Whether this path is a symbolic link."""
try:
return self._is_symlink
except AttributeError:
Expand All @@ -120,7 +126,7 @@ def is_symlink(self):

class _PosixPathStatus(_PathStatusBase):
"""Implementation of pathlib.types.Status that provides file status
information. Don't try to construct it yourself."""
information for POSIX paths. Don't try to construct it yourself."""
__slots__ = ('_mode',)

def __init__(self, path):
Expand All @@ -145,27 +151,19 @@ def _get_mode(self, *, follow_symlinks=True):
return mode

def exists(self, *, follow_symlinks=True):
"""
Whether this path exists
"""
"""Whether this path exists."""
return self._get_mode(follow_symlinks=follow_symlinks) > 0

def is_dir(self, *, follow_symlinks=True):
"""
Whether this path is a directory.
"""
"""Whether this path is a directory."""
return S_ISDIR(self._get_mode(follow_symlinks=follow_symlinks))

def is_file(self, *, follow_symlinks=True):
"""
Whether this path is a regular file.
"""
"""Whether this path is a regular file."""
return S_ISREG(self._get_mode(follow_symlinks=follow_symlinks))

def is_symlink(self):
"""
Whether this path is a symbolic link.
"""
"""Whether this path is a symbolic link."""
return S_ISLNK(self._get_mode(follow_symlinks=False))


Expand All @@ -183,9 +181,7 @@ def __init__(self, path, entry):
self._entry = entry

def exists(self, *, follow_symlinks=True):
"""
Whether this path exists
"""
"""Whether this path exists."""
if not follow_symlinks:
return True
try:
Expand All @@ -200,27 +196,21 @@ def exists(self, *, follow_symlinks=True):
return self._exists

def is_dir(self, *, follow_symlinks=True):
"""
Whether this path is a directory.
"""
"""Whether this path is a directory."""
try:
return self._entry.is_dir(follow_symlinks=follow_symlinks)
except OSError:
return False

def is_file(self, *, follow_symlinks=True):
"""
Whether this path is a regular file.
"""
"""Whether this path is a regular file."""
try:
return self._entry.is_file(follow_symlinks=follow_symlinks)
except OSError:
return False

def is_symlink(self):
"""
Whether this path is a symbolic link.
"""
"""Whether this path is a symbolic link."""
try:
return self._entry.is_symlink()
except OSError:
Expand Down