[Python-checkins] bpo-40107: Switch to using io.open() for pathlib.Path.open() (GH-25240)

zooba webhook-mailer at python.org
Fri Apr 9 16:52:56 EDT 2021


https://github.com/python/cpython/commit/11c3bd3f6d06649484b81a659c7bf02d6632e607
commit: 11c3bd3f6d06649484b81a659c7bf02d6632e607
branch: master
author: Barney Gale <barney.gale at gmail.com>
committer: zooba <steve.dower at microsoft.com>
date: 2021-04-09T21:52:49+01:00
summary:

bpo-40107: Switch to using io.open() for pathlib.Path.open() (GH-25240)

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.

files:
M Lib/pathlib.py

diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 19d45a3d2ba78..1518d49f2212b 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -350,7 +350,7 @@ class _NormalAccessor(_Accessor):
 
     stat = os.stat
 
-    open = os.open
+    open = io.open
 
     listdir = os.listdir
 
@@ -1046,10 +1046,6 @@ def __exit__(self, t, v, tb):
         # 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 @@ def open(self, mode='r', buffering=-1, encoding=None,
         """
         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):
         """



More information about the Python-checkins mailing list