Skip to content

Commit

Permalink
pythonGH-112906: Fix performance regression in pathlib path initialis…
Browse files Browse the repository at this point in the history
…ation

This was caused by 76929fd, specifically its use of `super()` and its
packing/unpacking `*args`.
  • Loading branch information
barneygale committed Dec 9, 2023
1 parent c1652d6 commit 911df8d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Lib/pathlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __new__(cls, *args, **kwargs):
cls = PureWindowsPath if os.name == 'nt' else PurePosixPath
return object.__new__(cls)

def __init__(self, *args):
def _load_args(self, args):
paths = []
for arg in args:
if isinstance(arg, PurePath):
Expand All @@ -90,7 +90,7 @@ def __init__(self, *args):
"object where __fspath__ returns a str, "
f"not {type(path).__name__!r}")
paths.append(path)
super().__init__(*paths)
return paths

def __reduce__(self):
# Using the parts tuple helps share interned path parts
Expand Down
8 changes: 6 additions & 2 deletions Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,14 @@ class PurePathBase:
)
pathmod = os.path

def __init__(self, *paths):
self._raw_paths = paths
def __init__(self, *args):
self._raw_paths = self._load_args(args)
self._resolving = False

def _load_args(self, args):
# overridden in pathlib.PurePath
return args

def with_segments(self, *pathsegments):
"""Construct a new path object from any number of path-like objects.
Subclasses may override this method to customize how new path objects
Expand Down

0 comments on commit 911df8d

Please sign in to comment.