[Python-checkins] bpo-40038: pathlib: remove partial support for preserving accessor when modifying a path (GH-19342)

zooba webhook-mailer at python.org
Tue Apr 6 20:26:41 EDT 2021


https://github.com/python/cpython/commit/2219187cab6bca009c42b63b2f4c30b5b10c916d
commit: 2219187cab6bca009c42b63b2f4c30b5b10c916d
branch: master
author: Barney Gale <barney.gale at gmail.com>
committer: zooba <steve.dower at microsoft.com>
date: 2021-04-07T01:26:37+01:00
summary:

bpo-40038: pathlib: remove partial support for preserving accessor when modifying a path (GH-19342)

files:
M Lib/pathlib.py

diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index cd5884d87d520..9db8ae2d8a389 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -697,7 +697,7 @@ def _parse_args(cls, args):
         return cls._flavour.parse_parts(parts)
 
     @classmethod
-    def _from_parts(cls, args, init=True):
+    def _from_parts(cls, args):
         # We need to call _parse_args on the instance, so as to get the
         # right flavour.
         self = object.__new__(cls)
@@ -705,18 +705,14 @@ def _from_parts(cls, args, init=True):
         self._drv = drv
         self._root = root
         self._parts = parts
-        if init:
-            self._init()
         return self
 
     @classmethod
-    def _from_parsed_parts(cls, drv, root, parts, init=True):
+    def _from_parsed_parts(cls, drv, root, parts):
         self = object.__new__(cls)
         self._drv = drv
         self._root = root
         self._parts = parts
-        if init:
-            self._init()
         return self
 
     @classmethod
@@ -726,10 +722,6 @@ def _format_parsed_parts(cls, drv, root, parts):
         else:
             return cls._flavour.join(parts)
 
-    def _init(self):
-        # Overridden in concrete Path
-        pass
-
     def _make_child(self, args):
         drv, root, parts = self._parse_args(args)
         drv, root, parts = self._flavour.join_parsed_parts(
@@ -1069,29 +1061,18 @@ class Path(PurePath):
     object. You can also instantiate a PosixPath or WindowsPath directly,
     but cannot instantiate a WindowsPath on a POSIX system or vice versa.
     """
-    __slots__ = (
-        '_accessor',
-    )
+    _accessor = _normal_accessor
+    __slots__ = ()
 
     def __new__(cls, *args, **kwargs):
         if cls is Path:
             cls = WindowsPath if os.name == 'nt' else PosixPath
-        self = cls._from_parts(args, init=False)
+        self = cls._from_parts(args)
         if not self._flavour.is_supported:
             raise NotImplementedError("cannot instantiate %r on your system"
                                       % (cls.__name__,))
-        self._init()
         return self
 
-    def _init(self,
-              # Private non-constructor arguments
-              template=None,
-              ):
-        if template is not None:
-            self._accessor = template._accessor
-        else:
-            self._accessor = _normal_accessor
-
     def _make_child_relpath(self, part):
         # This is an optimization used for dir walking.  `part` must be
         # a single part relative to this path.
@@ -1192,9 +1173,7 @@ def absolute(self):
             return self
         # FIXME this must defer to the specific flavour (and, under Windows,
         # use nt._getfullpathname())
-        obj = self._from_parts([os.getcwd()] + self._parts, init=False)
-        obj._init(template=self)
-        return obj
+        return self._from_parts([os.getcwd()] + self._parts)
 
     def resolve(self, strict=False):
         """
@@ -1210,9 +1189,7 @@ def resolve(self, strict=False):
             s = str(self.absolute())
         # Now we have no symlinks in the path, it's safe to normalize it.
         normed = self._flavour.pathmod.normpath(s)
-        obj = self._from_parts((normed,), init=False)
-        obj._init(template=self)
-        return obj
+        return self._from_parts((normed,))
 
     def stat(self):
         """
@@ -1284,9 +1261,7 @@ def readlink(self):
         Return the path to which the symbolic link points.
         """
         path = self._accessor.readlink(self)
-        obj = self._from_parts((path,), init=False)
-        obj._init(template=self)
-        return obj
+        return self._from_parts((path,))
 
     def touch(self, mode=0o666, exist_ok=True):
         """



More information about the Python-checkins mailing list