]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40107: Switch to using io.open() for pathlib.Path.open() (GH-25240)
authorBarney Gale <barney.gale@gmail.com>
Fri, 9 Apr 2021 20:52:49 +0000 (21:52 +0100)
committerGitHub <noreply@github.com>
Fri, 9 Apr 2021 20:52:49 +0000 (21:52 +0100)
Previously we had identical behaviour but only allowed accessors to override os.open(). This change allows the override to also construct the IO wrapper as well.

Lib/pathlib.py

index 19d45a3d2ba786fbebb6fae5e506e6958a665829..1518d49f2212b2828a4a757ee4ef5532bdd39794 100644 (file)
@@ -350,7 +350,7 @@ class _NormalAccessor(_Accessor):
 
     stat = os.stat
 
-    open = os.open
+    open = io.open
 
     listdir = os.listdir
 
@@ -1046,10 +1046,6 @@ class Path(PurePath):
         # removed in the future.
         pass
 
-    def _opener(self, name, flags, mode=0o666):
-        # A stub for the opener argument to built-in open()
-        return self._accessor.open(self, flags, mode)
-
     # Public API
 
     @classmethod
@@ -1171,8 +1167,8 @@ class Path(PurePath):
         """
         if "b" not in mode:
             encoding = io.text_encoding(encoding)
-        return io.open(self, mode, buffering, encoding, errors, newline,
-                       opener=self._opener)
+        return self._accessor.open(self, mode, buffering, encoding, errors,
+                                   newline)
 
     def read_bytes(self):
         """