Skip to content

Commit 2219187

Browse files
authored
bpo-40038: pathlib: remove partial support for preserving accessor when modifying a path (GH-19342)
1 parent 986da8e commit 2219187

File tree

1 file changed

+8
-33
lines changed

1 file changed

+8
-33
lines changed

Lib/pathlib.py

+8-33
Original file line numberDiff line numberDiff line change
@@ -697,26 +697,22 @@ def _parse_args(cls, args):
697697
return cls._flavour.parse_parts(parts)
698698

699699
@classmethod
700-
def _from_parts(cls, args, init=True):
700+
def _from_parts(cls, args):
701701
# We need to call _parse_args on the instance, so as to get the
702702
# right flavour.
703703
self = object.__new__(cls)
704704
drv, root, parts = self._parse_args(args)
705705
self._drv = drv
706706
self._root = root
707707
self._parts = parts
708-
if init:
709-
self._init()
710708
return self
711709

712710
@classmethod
713-
def _from_parsed_parts(cls, drv, root, parts, init=True):
711+
def _from_parsed_parts(cls, drv, root, parts):
714712
self = object.__new__(cls)
715713
self._drv = drv
716714
self._root = root
717715
self._parts = parts
718-
if init:
719-
self._init()
720716
return self
721717

722718
@classmethod
@@ -726,10 +722,6 @@ def _format_parsed_parts(cls, drv, root, parts):
726722
else:
727723
return cls._flavour.join(parts)
728724

729-
def _init(self):
730-
# Overridden in concrete Path
731-
pass
732-
733725
def _make_child(self, args):
734726
drv, root, parts = self._parse_args(args)
735727
drv, root, parts = self._flavour.join_parsed_parts(
@@ -1069,29 +1061,18 @@ class Path(PurePath):
10691061
object. You can also instantiate a PosixPath or WindowsPath directly,
10701062
but cannot instantiate a WindowsPath on a POSIX system or vice versa.
10711063
"""
1072-
__slots__ = (
1073-
'_accessor',
1074-
)
1064+
_accessor = _normal_accessor
1065+
__slots__ = ()
10751066

10761067
def __new__(cls, *args, **kwargs):
10771068
if cls is Path:
10781069
cls = WindowsPath if os.name == 'nt' else PosixPath
1079-
self = cls._from_parts(args, init=False)
1070+
self = cls._from_parts(args)
10801071
if not self._flavour.is_supported:
10811072
raise NotImplementedError("cannot instantiate %r on your system"
10821073
% (cls.__name__,))
1083-
self._init()
10841074
return self
10851075

1086-
def _init(self,
1087-
# Private non-constructor arguments
1088-
template=None,
1089-
):
1090-
if template is not None:
1091-
self._accessor = template._accessor
1092-
else:
1093-
self._accessor = _normal_accessor
1094-
10951076
def _make_child_relpath(self, part):
10961077
# This is an optimization used for dir walking. `part` must be
10971078
# a single part relative to this path.
@@ -1192,9 +1173,7 @@ def absolute(self):
11921173
return self
11931174
# FIXME this must defer to the specific flavour (and, under Windows,
11941175
# use nt._getfullpathname())
1195-
obj = self._from_parts([os.getcwd()] + self._parts, init=False)
1196-
obj._init(template=self)
1197-
return obj
1176+
return self._from_parts([os.getcwd()] + self._parts)
11981177

11991178
def resolve(self, strict=False):
12001179
"""
@@ -1210,9 +1189,7 @@ def resolve(self, strict=False):
12101189
s = str(self.absolute())
12111190
# Now we have no symlinks in the path, it's safe to normalize it.
12121191
normed = self._flavour.pathmod.normpath(s)
1213-
obj = self._from_parts((normed,), init=False)
1214-
obj._init(template=self)
1215-
return obj
1192+
return self._from_parts((normed,))
12161193

12171194
def stat(self):
12181195
"""
@@ -1284,9 +1261,7 @@ def readlink(self):
12841261
Return the path to which the symbolic link points.
12851262
"""
12861263
path = self._accessor.readlink(self)
1287-
obj = self._from_parts((path,), init=False)
1288-
obj._init(template=self)
1289-
return obj
1264+
return self._from_parts((path,))
12901265

12911266
def touch(self, mode=0o666, exist_ok=True):
12921267
"""

0 commit comments

Comments
 (0)