@@ -1623,25 +1623,28 @@ expression support in the :mod:`re` module).
1623
1623
1624
1624
.. method :: str.encode(encoding="utf-8", errors="strict")
1625
1625
1626
- Return an encoded version of the string as a bytes object. Default encoding
1627
- is ``'utf-8' ``. *errors * may be given to set a different error handling scheme.
1628
- The default for *errors * is ``'strict' ``, meaning that encoding errors raise
1629
- a :exc: `UnicodeError `. Other possible
1630
- values are ``'ignore' ``, ``'replace' ``, ``'xmlcharrefreplace' ``,
1631
- ``'backslashreplace' `` and any other name registered via
1632
- :func: `codecs.register_error `, see section :ref: `error-handlers `. For a
1633
- list of possible encodings, see section :ref: `standard-encodings `.
1634
-
1635
- By default, the *errors * argument is not checked for best performances, but
1636
- only used at the first encoding error. Enable the :ref: `Python Development
1637
- Mode <devmode>`, or use a :ref: `debug build <debug-build >` to check
1638
- *errors *.
1626
+ Return the string encoded to :class: `bytes `.
1627
+
1628
+ *encoding * defaults to ``'utf-8' ``;
1629
+ see :ref: `standard-encodings ` for possible values.
1630
+
1631
+ *errors * controls how encoding errors are handled.
1632
+ If ``'strict' `` (the default), a :exc: `UnicodeError ` exception is raised.
1633
+ Other possible values are ``'ignore' ``,
1634
+ ``'replace' ``, ``'xmlcharrefreplace' ``, ``'backslashreplace' `` and any
1635
+ other name registered via :func: `codecs.register_error `.
1636
+ See :ref: `error-handlers ` for details.
1637
+
1638
+ For performance reasons, the value of *errors * is not checked for validity
1639
+ unless an encoding error actually occurs,
1640
+ :ref: `devmode ` is enabled
1641
+ or a :ref: `debug build <debug-build >` is used.
1639
1642
1640
1643
.. versionchanged :: 3.1
1641
- Support for keyword arguments added .
1644
+ Added support for keyword arguments.
1642
1645
1643
1646
.. versionchanged :: 3.9
1644
- The *errors * is now checked in development mode and
1647
+ The value of the *errors * argument is now checked in :ref: ` devmode ` and
1645
1648
in :ref: `debug mode <debug-build >`.
1646
1649
1647
1650
@@ -2755,29 +2758,32 @@ arbitrary binary data.
2755
2758
.. method :: bytes.decode(encoding="utf-8", errors="strict")
2756
2759
bytearray.decode(encoding="utf-8", errors="strict")
2757
2760
2758
- Return a string decoded from the given bytes. Default encoding is
2759
- ``'utf-8' ``. *errors * may be given to set a different
2760
- error handling scheme. The default for *errors * is ``'strict' ``, meaning
2761
- that encoding errors raise a :exc: `UnicodeError `. Other possible values are
2762
- ``'ignore' ``, ``'replace' `` and any other name registered via
2763
- :func: `codecs.register_error `, see section :ref: `error-handlers `. For a
2764
- list of possible encodings, see section :ref: `standard-encodings `.
2761
+ Return the bytes decoded to a :class: `str `.
2762
+
2763
+ *encoding * defaults to ``'utf-8' ``;
2764
+ see :ref: `standard-encodings ` for possible values.
2765
+
2766
+ *errors * controls how decoding errors are handled.
2767
+ If ``'strict' `` (the default), a :exc: `UnicodeError ` exception is raised.
2768
+ Other possible values are ``'ignore' ``, ``'replace' ``,
2769
+ and any other name registered via :func: `codecs.register_error `.
2770
+ See :ref: `error-handlers ` for details.
2765
2771
2766
- By default , the *errors * argument is not checked for best performances, but
2767
- only used at the first decoding error. Enable the :ref: ` Python Development
2768
- Mode < devmode>`, or use a :ref: `debug build <debug-build >` to check * errors * .
2772
+ For performance reasons , the value of *errors * is not checked for validity
2773
+ unless a decoding error actually occurs,
2774
+ :ref: ` devmode ` is enabled or a :ref: `debug build <debug-build >` is used .
2769
2775
2770
2776
.. note ::
2771
2777
2772
2778
Passing the *encoding * argument to :class: `str ` allows decoding any
2773
2779
:term: `bytes-like object ` directly, without needing to make a temporary
2774
- bytes or bytearray object.
2780
+ :class: ` ! bytes` or :class: ` ! bytearray` object.
2775
2781
2776
2782
.. versionchanged :: 3.1
2777
2783
Added support for keyword arguments.
2778
2784
2779
2785
.. versionchanged :: 3.9
2780
- The *errors * is now checked in development mode and
2786
+ The value of the *errors * argument is now checked in :ref: ` devmode ` and
2781
2787
in :ref: `debug mode <debug-build >`.
2782
2788
2783
2789
0 commit comments