summaryrefslogtreecommitdiff
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
authorAlexey Izbyshev <izbyshev@ispras.ru>2018-10-20 03:22:31 +0300
committerVictor Stinner <vstinner@redhat.com>2018-10-20 02:22:31 +0200
commita2670565d8f5c502388378aba1fe73023fd8c8d4 (patch)
treea9f3a5f8e2a123aaff4f27a94c33580f0216dccd /Lib/_pyio.py
parent4acf6c9d4be77b968fa498569d7a1545e5e77344 (diff)
downloadcpython-git-a2670565d8f5c502388378aba1fe73023fd8c8d4.tar.gz
bpo-32236: open() emits RuntimeWarning if buffering=1 for binary mode (GH-4842)
If buffering=1 is specified for open() in binary mode, it is silently treated as buffering=-1 (i.e., the default buffer size). Coupled with the fact that line buffering is always supported in Python 2, such behavior caused several issues (e.g., bpo-10344, bpo-21332). Warn that line buffering is not supported if open() is called with binary mode and buffering=1.
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r--Lib/_pyio.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 01ef5b7b0b..b8975ff533 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -198,6 +198,11 @@ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
raise ValueError("binary mode doesn't take an errors argument")
if binary and newline is not None:
raise ValueError("binary mode doesn't take a newline argument")
+ if binary and buffering == 1:
+ import warnings
+ warnings.warn("line buffering (buffering=1) isn't supported in binary "
+ "mode, the default buffer size will be used",
+ RuntimeWarning, 2)
raw = FileIO(file,
(creating and "x" or "") +
(reading and "r" or "") +