Skip to content

Commit 11c3bd3

Browse files
authored
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.
1 parent 2d7fdc9 commit 11c3bd3

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Lib/pathlib.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ class _NormalAccessor(_Accessor):
350350

351351
stat = os.stat
352352

353-
open = os.open
353+
open = io.open
354354

355355
listdir = os.listdir
356356

@@ -1046,10 +1046,6 @@ def __exit__(self, t, v, tb):
10461046
# removed in the future.
10471047
pass
10481048

1049-
def _opener(self, name, flags, mode=0o666):
1050-
# A stub for the opener argument to built-in open()
1051-
return self._accessor.open(self, flags, mode)
1052-
10531049
# Public API
10541050

10551051
@classmethod
@@ -1171,8 +1167,8 @@ def open(self, mode='r', buffering=-1, encoding=None,
11711167
"""
11721168
if "b" not in mode:
11731169
encoding = io.text_encoding(encoding)
1174-
return io.open(self, mode, buffering, encoding, errors, newline,
1175-
opener=self._opener)
1170+
return self._accessor.open(self, mode, buffering, encoding, errors,
1171+
newline)
11761172

11771173
def read_bytes(self):
11781174
"""

0 commit comments

Comments
 (0)