@@ -1585,25 +1585,28 @@ expression support in the :mod:`re` module).
1585
1585
1586
1586
.. method :: str.encode(encoding="utf-8", errors="strict")
1587
1587
1588
- Return an encoded version of the string as a bytes object. Default encoding
1589
- is ``'utf-8' ``. *errors * may be given to set a different error handling scheme.
1590
- The default for *errors * is ``'strict' ``, meaning that encoding errors raise
1591
- a :exc: `UnicodeError `. Other possible
1592
- values are ``'ignore' ``, ``'replace' ``, ``'xmlcharrefreplace' ``,
1593
- ``'backslashreplace' `` and any other name registered via
1594
- :func: `codecs.register_error `, see section :ref: `error-handlers `. For a
1595
- list of possible encodings, see section :ref: `standard-encodings `.
1596
-
1597
- By default, the *errors * argument is not checked for best performances, but
1598
- only used at the first encoding error. Enable the :ref: `Python Development
1599
- Mode <devmode>`, or use a :ref: `debug build <debug-build >` to check
1600
- *errors *.
1588
+ Return the string encoded to :class: `bytes `.
1589
+
1590
+ *encoding * defaults to ``'utf-8' ``;
1591
+ see :ref: `standard-encodings ` for possible values.
1592
+
1593
+ *errors * controls how encoding errors are handled.
1594
+ If ``'strict' `` (the default), a :exc: `UnicodeError ` exception is raised.
1595
+ Other possible values are ``'ignore' ``,
1596
+ ``'replace' ``, ``'xmlcharrefreplace' ``, ``'backslashreplace' `` and any
1597
+ other name registered via :func: `codecs.register_error `.
1598
+ See :ref: `error-handlers ` for details.
1599
+
1600
+ For performance reasons, the value of *errors * is not checked for validity
1601
+ unless an encoding error actually occurs,
1602
+ :ref: `devmode ` is enabled
1603
+ or a :ref: `debug build <debug-build >` is used.
1601
1604
1602
1605
.. versionchanged :: 3.1
1603
- Support for keyword arguments added .
1606
+ Added support for keyword arguments.
1604
1607
1605
1608
.. versionchanged :: 3.9
1606
- The *errors * is now checked in development mode and
1609
+ The value of the *errors * argument is now checked in :ref: ` devmode ` and
1607
1610
in :ref: `debug mode <debug-build >`.
1608
1611
1609
1612
@@ -2715,29 +2718,32 @@ arbitrary binary data.
2715
2718
.. method :: bytes.decode(encoding="utf-8", errors="strict")
2716
2719
bytearray.decode(encoding="utf-8", errors="strict")
2717
2720
2718
- Return a string decoded from the given bytes. Default encoding is
2719
- ``'utf-8' ``. *errors * may be given to set a different
2720
- error handling scheme. The default for *errors * is ``'strict' ``, meaning
2721
- that encoding errors raise a :exc: `UnicodeError `. Other possible values are
2722
- ``'ignore' ``, ``'replace' `` and any other name registered via
2723
- :func: `codecs.register_error `, see section :ref: `error-handlers `. For a
2724
- list of possible encodings, see section :ref: `standard-encodings `.
2721
+ Return the bytes decoded to a :class: `str `.
2722
+
2723
+ *encoding * defaults to ``'utf-8' ``;
2724
+ see :ref: `standard-encodings ` for possible values.
2725
+
2726
+ *errors * controls how decoding errors are handled.
2727
+ If ``'strict' `` (the default), a :exc: `UnicodeError ` exception is raised.
2728
+ Other possible values are ``'ignore' ``, ``'replace' ``,
2729
+ and any other name registered via :func: `codecs.register_error `.
2730
+ See :ref: `error-handlers ` for details.
2725
2731
2726
- By default , the *errors * argument is not checked for best performances, but
2727
- only used at the first decoding error. Enable the :ref: ` Python Development
2728
- Mode < devmode>`, or use a :ref: `debug build <debug-build >` to check * errors * .
2732
+ For performance reasons , the value of *errors * is not checked for validity
2733
+ unless a decoding error actually occurs,
2734
+ :ref: ` devmode ` is enabled or a :ref: `debug build <debug-build >` is used .
2729
2735
2730
2736
.. note ::
2731
2737
2732
2738
Passing the *encoding * argument to :class: `str ` allows decoding any
2733
2739
:term: `bytes-like object ` directly, without needing to make a temporary
2734
- bytes or bytearray object.
2740
+ :class: ` ! bytes` or :class: ` ! bytearray` object.
2735
2741
2736
2742
.. versionchanged :: 3.1
2737
2743
Added support for keyword arguments.
2738
2744
2739
2745
.. versionchanged :: 3.9
2740
- The *errors * is now checked in development mode and
2746
+ The value of the *errors * argument is now checked in :ref: ` devmode ` and
2741
2747
in :ref: `debug mode <debug-build >`.
2742
2748
2743
2749
0 commit comments