Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GH-101362: Omit path anchor frompathlib.PurePath()._parts#102476

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes from1 commit
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
8bf4600
GH-101362: Omit path anchor from `pathlib.PurePath()._parts`
barneygaleMar 6, 2023
e7a58c3
Add news blurb.
barneygaleMar 6, 2023
1d58aed
Rename `_parts` to `_tail` for clarity.
barneygaleMar 6, 2023
ac26f84
Merge branch 'main' into gh-101362-exclude-anchor-from-parts
barneygaleMar 10, 2023
cce5d7b
Undo some changes to _format_parsed_parts()
barneygaleMar 10, 2023
f529d51
Merge branch 'main' into gh-101362-exclude-anchor-from-parts
barneygaleApr 3, 2023
0c0f5bd
Move `str()` call out of initialiser.
barneygaleApr 3, 2023
7a4e92f
Optimize `_make_child_relpath()`
barneygaleApr 3, 2023
c8d4b38
Remove caching of `Path.parts`
barneygaleApr 3, 2023
d2a578d
Cache case-normalized string.
barneygaleApr 6, 2023
de4df7a
Rename `_make_child` back to `_make_child_relpath`
barneygaleApr 7, 2023
5a34f7e
Add comments to `PurePath.__slots__`
barneygaleApr 8, 2023
078ced9
Merge branch 'main' into gh-101362-exclude-anchor-from-parts
barneygaleApr 9, 2023
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
PrevPrevious commit
NextNext commit
Optimize_make_child_relpath()
  • Loading branch information
@barneygale
barneygale committedApr 3, 2023
commit7a4e92fdf1d87d5f6b560c118e3ce827082619cd
30 changes: 20 additions & 10 deletionsLib/pathlib.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -120,7 +120,7 @@ def __init__(self, name, child_parts, flavour):

def _select_from(self, parent_path, is_dir, exists, scandir, normcase):
try:
path = parent_path._make_child_relpath(self.name)
path = parent_path._make_child(self.name)
if (is_dir if self.dironly else exists)(path):
for p in self.successor._select_from(path, is_dir, exists, scandir, normcase):
yield p
Expand DownExpand Up@@ -154,7 +154,7 @@ def _select_from(self, parent_path, is_dir, exists, scandir, normcase):
continue
name = entry.name
if self.match(normcase(name)):
path = parent_path._make_child_relpath(name)
path = parent_path._make_child(name)
for p in self.successor._select_from(path, is_dir, exists, scandir, normcase):
yield p
except PermissionError:
Expand All@@ -181,7 +181,7 @@ def _iterate_directories(self, parent_path, is_dir, scandir):
if not _ignore_error(e):
raise
if entry_is_dir and not entry.is_symlink():
path = parent_path._make_child_relpath(entry.name)
path = parent_path._make_child(entry.name)
for p in self._iterate_directories(path, is_dir, scandir):
yield p
except PermissionError:
Expand DownExpand Up@@ -703,11 +703,21 @@ def __new__(cls, *args, **kwargs):
cls = WindowsPath if os.name == 'nt' else PosixPath
return object.__new__(cls)

def _make_child_relpath(self, part):
# This is an optimization used for dir walking. `part` must be
# a single part relative to this path.
tail = self._tail + [part]
return self._from_parsed_parts(self.drive, self.root, tail)
def _make_child(self, name):
path_str = str(self)
tail = self._tail
if tail:
path_str = f'{path_str}{self._flavour.sep}{name}'
elif path_str != '.':
path_str = f'{path_str}{name}'
else:
path_str = name
path = type(self)(path_str)
path._str = path_str
path._drv = self.drive
path._root = self.root
path._tail_cached = tail + [name]
return path

def __enter__(self):
# In previous versions of pathlib, __exit__() marked this path as
Expand DownExpand Up@@ -762,7 +772,7 @@ def iterdir(self):
special entries '.' and '..' are not included.
"""
for name in os.listdir(self):
yield self._make_child_relpath(name)
yield self._make_child(name)

def _scandir(self):
# bpo-24132: a future version of pathlib will support subclassing of
Expand DownExpand Up@@ -1244,7 +1254,7 @@ def walk(self, top_down=True, on_error=None, follow_symlinks=False):
else:
paths.append((path, dirnames, filenames))

paths += [path._make_child_relpath(d) for d in reversed(dirnames)]
paths += [path._make_child(d) for d in reversed(dirnames)]


class PosixPath(Path, PurePosixPath):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp