Skip to content

Commit aa307bf

Browse files
Change documentation to reflect the new docstring adjustments in 3.13
1 parent 2db9573 commit aa307bf

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Doc/library/functions.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,12 @@ are always available. They are listed here in alphabetical order.
340340
It is needed to unambiguous :ref:`filter <warning-filter>` syntax warnings
341341
by module name.
342342

343-
This function raises :exc:`SyntaxError` if the compiled source is invalid,
344-
and :exc:`ValueError` if the source contains null bytes.
343+
This function raises the following exceptions:
344+
345+
- :exc:`SyntaxError` if the compiled source is invalid
346+
- :exc:`ValueError` if the source contains null bytes
347+
- :exc:`UnicodeDecodeError` if the source code contains docstrings that
348+
cannot be encoded as UTF-8 and the optimization level is below ``2``
345349

346350
If you want to parse Python code into its AST representation, see
347351
:func:`ast.parse`.
@@ -373,6 +377,11 @@ are always available. They are listed here in alphabetical order.
373377
Previously, :exc:`TypeError` was raised when null bytes were encountered
374378
in *source*.
375379

380+
.. versionchanged:: 3.13
381+
:exc:`UnicodeDecodeError` is now raised if any docstring in *source*
382+
contains surrogates (like ``\ud800``) and therefore cannot be encoded
383+
as UTF-8.
384+
376385
.. versionadded:: 3.8
377386
``ast.PyCF_ALLOW_TOP_LEVEL_AWAIT`` can now be passed in flags to enable
378387
support for top-level ``await``, ``async for``, and ``async with``.

Doc/tutorial/controlflow.rst

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,17 +1039,8 @@ blank, visually separating the summary from the rest of the description. The
10391039
following lines should be one or more paragraphs describing the object's calling
10401040
conventions, its side effects, etc.
10411041

1042-
The Python parser does not strip indentation from multi-line string literals in
1043-
Python, so tools that process documentation have to strip indentation if
1044-
desired. This is done using the following convention. The first non-blank line
1045-
*after* the first line of the string determines the amount of indentation for
1046-
the entire documentation string. (We can't use the first line since it is
1047-
generally adjacent to the string's opening quotes so its indentation is not
1048-
apparent in the string literal.) Whitespace "equivalent" to this indentation is
1049-
then stripped from the start of all lines of the string. Lines that are
1050-
indented less should not occur, but if they occur all their leading whitespace
1051-
should be stripped. Equivalence of whitespace should be tested after expansion
1052-
of tabs (to 8 spaces, normally).
1042+
The Python parser strips indentation from multi-line string literals when they
1043+
serve as module, class, or function docstrings.
10531044

10541045
Here is an example of a multi-line docstring::
10551046

0 commit comments

Comments
 (0)