Skip to content

Commit b382e40

Browse files
committed
Matching against dot-prefixed path is fine (and faster!)
1 parent 6abb80d commit b382e40

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Lib/pathlib/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,13 +587,14 @@ def iterdir(self):
587587
def _scandir(self):
588588
return os.scandir(self)
589589

590-
def _entry_str(self, entry):
590+
@classmethod
591+
def _entry_str(cls, entry):
591592
# Transform an entry yielded from _scandir() into a path string.
592-
return entry.name if str(self) == '.' else entry.path
593+
return entry.path
593594

594595
def _make_child_entry(self, entry):
595596
# Transform an entry yielded from _scandir() into a path object.
596-
path_str = self._entry_str(entry)
597+
path_str = entry.name if str(self) == '.' else entry.path
597598
path = self.with_segments(path_str)
598599
path._str = path_str
599600
path._drv = self.drive

Lib/pathlib/_abc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ def _scandir(self):
753753
from contextlib import nullcontext
754754
return nullcontext(self.iterdir())
755755

756-
def _entry_str(self, entry):
756+
@classmethod
757+
def _entry_str(cls, entry):
757758
# Transform an entry yielded from _scandir() into a path string.
758759
return str(entry)
759760

0 commit comments

Comments
 (0)