Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0e2f5e7

Browse files
bizzyvinciCAM-Gerlach
authored andcommitted
pythongh-99991: improve docs on str.encode and bytes.decode (pythonGH-100198)
(cherry picked from commita2bb3b7)Co-authored-by: Bisola Olasehinde <horlasehinde@gmail.com>Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent73d2b15 commit0e2f5e7

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

‎Doc/library/stdtypes.rst‎

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,25 +1623,28 @@ expression support in the :mod:`re` module).
16231623

16241624
..method::str.encode(encoding="utf-8", errors="strict")
16251625

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.
16391642

16401643
..versionchanged::3.1
1641-
Supportfor keyword arguments added.
1644+
Added supportfor keyword arguments.
16421645

16431646
..versionchanged::3.9
1644-
The *errors* is now checked indevelopment mode and
1647+
Thevalue of the*errors*argumentis now checked in:ref:`devmode` and
16451648
in:ref:`debug mode<debug-build>`.
16461649

16471650

@@ -2755,29 +2758,32 @@ arbitrary binary data.
27552758
..method::bytes.decode(encoding="utf-8", errors="strict")
27562759
bytearray.decode(encoding="utf-8", errors="strict")
27572760

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.
27652771

2766-
By default, the *errors*argumentis not checked forbest performances, but
2767-
only used at the firstdecoding error. Enable the:ref:`Python Development
2768-
Mode <devmode>`, or usea:ref:`debug build<debug-build>`to check *errors*.
2772+
For performance reasons, thevalue of*errors* is not checked forvalidity
2773+
unless adecoding error actually occurs,
2774+
:ref:`devmode` is enabled ora:ref:`debug build<debug-build>`is used.
27692775

27702776
..note::
27712777

27722778
Passing the *encoding* argument to:class:`str` allows decoding any
27732779
:term:`bytes-like object` directly, without needing to make a temporary
2774-
bytes or bytearray object.
2780+
:class:`!bytes` or:class:`!bytearray` object.
27752781

27762782
..versionchanged::3.1
27772783
Added support for keyword arguments.
27782784

27792785
..versionchanged::3.9
2780-
The *errors* is now checked indevelopment mode and
2786+
Thevalue of the*errors*argumentis now checked in:ref:`devmode` and
27812787
in:ref:`debug mode<debug-build>`.
27822788

27832789

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp