]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-51511: Note that codecs.open()'s encoding parameter affects automatic conversion...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 21 Oct 2022 23:28:25 +0000 (16:28 -0700)
committerGitHub <noreply@github.com>
Fri, 21 Oct 2022 23:28:25 +0000 (16:28 -0700)
(cherry picked from commit d9407b174c81fda33e6c09a6f988c9a7cb8368af)

Co-authored-by: Stanley <46876382+slateny@users.noreply.github.com>
Doc/library/codecs.rst
Lib/codecs.py
Lib/test/test_codecs.py

index 1c10462c1509c39d37caa697c9776f7e503c5503..7d56327aad265e01951d843890721489e640974a 100644 (file)
@@ -189,7 +189,8 @@ wider range of codecs when working with binary files:
 
    .. note::
 
-      Underlying encoded files are always opened in binary mode.
+      If *encoding* is not ``None``, then the
+      underlying encoded files are always opened in binary mode.
       No automatic conversion of ``'\n'`` is done on reading and writing.
       The *mode* argument may be any binary mode acceptable to the built-in
       :func:`open` function; the ``'b'`` is automatically added.
index e6ad6e3a0523643fab643798d818e5e4927217d6..3b173b612101e7c635303a2129e3fe363791e2eb 100644 (file)
@@ -878,7 +878,8 @@ def open(filename, mode='r', encoding=None, errors='strict', buffering=-1):
         codecs. Output is also codec dependent and will usually be
         Unicode as well.
 
-        Underlying encoded files are always opened in binary mode.
+        If encoding is not None, then the
+        underlying encoded files are always opened in binary mode.
         The default file mode is 'r', meaning to open the file in read mode.
 
         encoding specifies the encoding which is to be used for the
index a9c43d9554beafa65ea3979fdfd24c4337141e63..8edd5ac0633e364e6be3f5775b1c9771b21d27b1 100644 (file)
@@ -705,7 +705,8 @@ class UTF16Test(ReadTest, unittest.TestCase):
                                          "spamspam", self.spambe)
 
     def test_bug691291(self):
-        # Files are always opened in binary mode, even if no binary mode was
+        # If encoding is not None, then
+        # files are always opened in binary mode, even if no binary mode was
         # specified.  This means that no automatic conversion of '\n' is done
         # on reading and writing.
         s1 = 'Hello\r\nworld\r\n'