]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-51511: Note that codecs.open()'s encoding parameter affects automatic conversion...
authorStanley <46876382+slateny@users.noreply.github.com>
Fri, 21 Oct 2022 23:01:05 +0000 (16:01 -0700)
committerGitHub <noreply@github.com>
Fri, 21 Oct 2022 23:01:05 +0000 (16:01 -0700)
Doc/library/codecs.rst
Lib/codecs.py
Lib/test/test_codecs.py

index 4a665f2254f8a6138a87ae3d4f760e9aa341f39f..8225236350d22ef1dac611327a6164b7a62151e4 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 5a1e7ec804009c5738a4e03de3dfc7ceef40bfc7..c1c55d8afef389a9187c1dad9f30028fa21613cc 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 57f3648eb7017cee359daac8bb8c1cd5c2de39f6..32a704f4e97e414a617d8284c7167734cba0c080 100644 (file)
@@ -708,7 +708,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'