8000 gh-51511: Note that codecs.open()'s encoding parameter affects automa… · python/cpython@dcb342b · GitHub
[go: up one dir, main page]

Skip to content

Commit dcb342b

Browse files
gh-51511: Note that codecs.open()'s encoding parameter affects automatic conversion to binary mode (GH-94370)
(cherry picked from commit d9407b1) Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
1 parent 0e4e058 commit dcb342b

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

Doc/library/codecs.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ wider range of codecs when working with binary files:
189189

190190
.. note::
191191

192-
Underlying encoded files are always opened in binary mode.
192+
If *encoding* is not ``None``, then the
193+
underlying encoded files are always opened in binary mode.
193194
No automatic conversion of ``'\n'`` is done on reading and writing.
194195
The *mode* argument may be any binary mode acceptable to the built-in
195196
:func:`open` function; the ``'b'`` is automatically added.

Lib/codecs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,8 @@ def open(filename, mode='r', encoding=None, errors='strict', buffering=-1):
878878
codecs. Output is also codec dependent and will usually be
879879
Unicode as well.
880880
881-
Underlying encoded files are always opened in binary mode.
881+
If encoding is not None, then the
882+
underlying encoded files are always opened in binary mode.
882883
The default file mode is 'r', meaning to open the file in read mode.
883884
884885
encoding specifies the encoding which is to be used for the

Lib/test/test_codecs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,8 @@ def test_decoder_state(self):
705705
"spamspam", self.spambe)
706706

707707
def test_bug691291(self):
708-
# Files are always opened in binary mode, even if no binary mode was
708+
# If encoding is not None, then
709+
# files are always opened in binary mode, even if no binary mode was
709710
# specified. This means that no automatic conversion of '\n' is done
710711
# on reading and writing.
711712
s1 = 'Hello\r\nworld\r\n'

0 commit comments

Comments
 (0)
0