aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--Lib/pathlib/_abc.py2
-rw-r--r--Lib/test/test_pathlib/test_pathlib_abc.py2
-rw-r--r--Misc/NEWS.d/next/Library/2024-07-22-08-57-28.gh-issue-120754.Eo5puP.rst1
3 files changed, 3 insertions, 2 deletions
diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py
index 500846d19cf..720756cac66 100644
--- a/Lib/pathlib/_abc.py
+++ b/Lib/pathlib/_abc.py
@@ -585,7 +585,7 @@ class PathBase(PurePathBase):
"""
Open the file in bytes mode, read it, and close the file.
"""
- with self.open(mode='rb') as f:
+ with self.open(mode='rb', buffering=0) as f:
return f.read()
def read_text(self, encoding=None, errors=None, newline=None):
diff --git a/Lib/test/test_pathlib/test_pathlib_abc.py b/Lib/test/test_pathlib/test_pathlib_abc.py
index 629a1d4bdeb..f222fd5b1ec 100644
--- a/Lib/test/test_pathlib/test_pathlib_abc.py
+++ b/Lib/test/test_pathlib/test_pathlib_abc.py
@@ -1464,7 +1464,7 @@ class DummyPath(PathBase):
def open(self, mode='r', buffering=-1, encoding=None,
errors=None, newline=None):
- if buffering != -1:
+ if buffering != -1 and not (buffering == 0 and 'b' in mode):
raise NotImplementedError
path_obj = self.resolve()
path = str(path_obj)
diff --git a/Misc/NEWS.d/next/Library/2024-07-22-08-57-28.gh-issue-120754.Eo5puP.rst b/Misc/NEWS.d/next/Library/2024-07-22-08-57-28.gh-issue-120754.Eo5puP.rst
new file mode 100644
index 00000000000..daf18415364
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-07-22-08-57-28.gh-issue-120754.Eo5puP.rst
@@ -0,0 +1 @@
+``Pathlib.read_bytes`` no longer opens the file in Python's buffered I/O mode. This reduces overheads as the code reads a file in whole leading to a modest speedup.