diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-06-25 22:51:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-25 22:51:05 (GMT) |
commit | 22eb689cf3de7972a2789db3ad01a86949508ab7 (patch) | |
tree | a1d63fa4cf235008e73f92a18ebef57be54ce4a5 /Doc | |
parent | e1a63c4f21011a3ae77dff624196561070c83446 (diff) | |
download | cpython-22eb689cf3de7972a2789db3ad01a86949508ab7.zip cpython-22eb689cf3de7972a2789db3ad01a86949508ab7.tar.gz cpython-22eb689cf3de7972a2789db3ad01a86949508ab7.tar.bz2 |
bpo-37388: Development mode check encoding and errors (GH-14341)
In development mode and in debug build, encoding and errors arguments
are now checked on string encoding and decoding operations. Examples:
open(), str.encode() and bytes.decode().
By default, for best performances, the errors argument is only
checked at the first encoding/decoding error, and the encoding
argument is sometimes ignored for empty strings.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/stdtypes.rst | 14 | ||||
-rw-r--r-- | Doc/using/cmdline.rst | 7 | ||||
-rw-r--r-- | Doc/whatsnew/3.9.rst | 9 |
3 files changed, 30 insertions, 0 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 35a17a1..8575f8a 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1559,9 +1559,16 @@ expression support in the :mod:`re` module). :func:`codecs.register_error`, see section :ref:`error-handlers`. For a list of possible encodings, see section :ref:`standard-encodings`. + By default, the *errors* argument is not checked for best performances, but + only used at the first encoding error. Enable the development mode + (:option:`-X` ``dev`` option), or use a debug build, to check *errors*. + .. versionchanged:: 3.1 Support for keyword arguments added. + .. versionchanged:: 3.9 + The *errors* is now checked in development mode and in debug mode. + .. method:: str.endswith(suffix[, start[, end]]) @@ -2575,6 +2582,10 @@ arbitrary binary data. :func:`codecs.register_error`, see section :ref:`error-handlers`. For a list of possible encodings, see section :ref:`standard-encodings`. + By default, the *errors* argument is not checked for best performances, but + only used at the first decoding error. Enable the development mode + (:option:`-X` ``dev`` option), or use a debug build, to check *errors*. + .. note:: Passing the *encoding* argument to :class:`str` allows decoding any @@ -2584,6 +2595,9 @@ arbitrary binary data. .. versionchanged:: 3.1 Added support for keyword arguments. + .. versionchanged:: 3.9 + The *errors* is now checked in development mode and in debug mode. + .. method:: bytes.endswith(suffix[, start[, end]]) bytearray.endswith(suffix[, start[, end]]) diff --git a/Doc/using/cmdline.rst b/Doc/using/cmdline.rst index 87af7e8..e11fe31 100644 --- a/Doc/using/cmdline.rst +++ b/Doc/using/cmdline.rst @@ -429,6 +429,9 @@ Miscellaneous options not be more verbose than the default if the code is correct: new warnings are only emitted when an issue is detected. Effect of the developer mode: + * Check *encoding* and *errors* arguments on string encoding and decoding + operations. Examples: :func:`open`, :meth:`str.encode` and + :meth:`bytes.decode`. * Add ``default`` warning filter, as :option:`-W` ``default``. * Install debug hooks on memory allocators: see the :c:func:`PyMem_SetupDebugHooks` C function. @@ -469,6 +472,10 @@ Miscellaneous options The ``-X pycache_prefix`` option. The ``-X dev`` option now logs ``close()`` exceptions in :class:`io.IOBase` destructor. + .. versionchanged:: 3.9 + Using ``-X dev`` option, check *encoding* and *errors* arguments on + string encoding and decoding operations. + Options you shouldn't use ~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index b58c99b..e9a31c8 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -84,6 +84,15 @@ Other Language Changes this case. (Contributed by Victor Stinner in :issue:`20443`.) +* In development mode and in debug build, *encoding* and *errors* arguments are + now checked on string encoding and decoding operations. Examples: + :func:`open`, :meth:`str.encode` and :meth:`bytes.decode`. + + By default, for best performances, the *errors* argument is only checked at + the first encoding/decoding error, and the *encoding* argument is sometimes + ignored for empty strings. + (Contributed by Victor Stinner in :issue:`37388`.) + New Modules =========== |