8000 bpo-30637: Improve the docs of ast.parse regarding differences with c… · python/cpython@f025ea2 · GitHub
[go: up one dir, main page]

Skip to content

Commit f025ea2

Browse files
bpo-30637: Improve the docs of ast.parse regarding differences with compile() (GH-28459)
(cherry picked from commit e6d05a4) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
1 parent db762a9 commit f025ea2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Doc/library/ast.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,19 @@ and classes for traversing abstract syntax trees:
19171917
``await`` as variable names. The lowest supported version is
19181918
8000 ``(3, 4)``; the highest is ``sys.version_info[0:2]``.
19191919

1920+
If source contains a null character ('\0'), :exc:`ValueError` is raised.
1921+
1922+
.. warning::
1923+
Note that succesfully parsing souce code into an AST object doesn't
1924+
guarantee that the source code provided is valid Python code that can
1925+
be executed as the compilation step can raise further :exc:`SyntaxError`
1926+
exceptions. For instance, the source ``return 42`` generates a valid
1927+
AST node for a return statement, but it cannot be compiled alone (it needs
1928+
to be inside a function node).
1929+
1930+
In particular, :func:`ast.parse` won't do any scoping checks, which the
1931+
compilation step does.
1932+
19201933
.. warning::
19211934
It is possible to crash the Python interpreter with a
19221935
sufficiently large/complex string due to stack depth limitations

0 commit comments

Comments
 (0)
0