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