diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index dd5dd5ca4e9e32..b43b61b69b6b9b 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -2155,7 +2155,9 @@ and classes for traversing abstract syntax trees: is no guarantee that the parse (or success of the parse) is the same as when run on the Python version corresponding to ``feature_version``. - If source contains a null character (``\0``), :exc:`ValueError` is raised. + This function raises :exc:`SyntaxError` if the parsed source is invalid. + It can also raise :exc:`ValueError`, :exc:`OverflowError` and + :exc:`RecursionError`. .. warning:: Note that successfully parsing source code into an AST object doesn't @@ -2176,6 +2178,10 @@ and classes for traversing abstract syntax trees: .. versionchanged:: 3.8 Added ``type_comments``, ``mode='func_type'`` and ``feature_version``. + .. versionchanged:: 3.12 + Previously, :exc:`ValueError` was raised instead of :exc:`SyntaxError` + when null characters (``\0``) were encountered in *source*. + .. versionchanged:: 3.13 The minimum supported version for ``feature_version`` is now ``(3, 7)``. The ``optimize`` argument was added. diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 2c649376efee70..8b92471cf4f289 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -334,8 +334,9 @@ are always available. They are listed here in alphabetical order. ``__debug__`` is true), ``1`` (asserts are removed, ``__debug__`` is false) or ``2`` (docstrings are removed too). - This function raises :exc:`SyntaxError` if the compiled source is invalid, - and :exc:`ValueError` if the source contains null bytes. + This function raises :exc:`SyntaxError` if the compiled source is invalid. + It can also raise :exc:`ValueError`, :exc:`OverflowError` and + :exc:`RecursionError`. If you want to parse Python code into its AST representation, see :func:`ast.parse`. @@ -371,6 +372,9 @@ are always available. They are listed here in alphabetical order. ``ast.PyCF_ALLOW_TOP_LEVEL_AWAIT`` can now be passed in flags to enable support for top-level ``await``, ``async for``, and ``async with``. + .. versionchanged:: 3.12 + Previously, :exc:`ValueError` was raised instead of :exc:`SyntaxError` when + null characters (``\0``) were encountered in *source*. .. class:: complex(number=0, /) complex(string, /)