Visitar URL original
GH-101362: Optimise pathlib by deferring path normalisation by barneygale · Pull Request #101560 · python/cpython · GitHub
Skip to content
Closed
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
Merge branch 'main' into optimize-pathlib-part-2b
  • Loading branch information
barneygale committed Mar 6, 2023
commit 76b2db76bbd17047d19f5e07b5b5639a4cae6a90
24 changes: 9 additions & 15 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,6 @@ def __reduce__(self):
def _parse_path(cls, path):
if not path:
return '', '', []
elif len(parts) == 1:
path = os.fspath(parts[0])
else:
path = cls._flavour.join(*parts)
sep = cls._flavour.sep
altsep = cls._flavour.altsep
if altsep:
Expand All @@ -300,9 +296,9 @@ def __init__(self, *args):
self._fspath = str(path) or '.'
else:
raise TypeError(
"argument should be a str object or an os.PathLike "
"object returning str, not %r"
% type(path))
"argument should be a str or an os.PathLike "
"object where __fspath__ returns a str, "
f"not {type(path).__name__!r}")
else:
self._fspath = '.'

Expand Down Expand Up @@ -649,10 +645,6 @@ def match(self, path_pattern):
drv, root, pat_parts = self._parse_path(path_pattern)
if not pat_parts:
raise ValueError("empty pattern")
elif drv and drv != self._flavour.normcase(self.drive):
return False
elif root and root != self.root:
return False
parts = self._parts_normcase
if drv or root:
if len(pat_parts) != len(parts):
Expand Down Expand Up @@ -713,9 +705,6 @@ def __init__(self, *args, **kwargs):
def __new__(cls, *args, **kwargs):
if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath
elif cls._flavour is not os.path:
raise NotImplementedError("cannot instantiate %r on your system"
% (cls.__name__,))
return super().__new__(cls)

def _make_child_relpath(self, part):
Expand Down Expand Up @@ -824,7 +813,12 @@ def absolute(self):
"""
if self.is_absolute():
return self
return type(self)(os.getcwd(), *self._parts)
elif self.drive:
# There is a CWD on each drive-letter drive.
cwd = self._flavour.abspath(self.drive)
else:
cwd = os.getcwd()
return type(self)(cwd, *self._parts)

def resolve(self, strict=False):
"""
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.