PyDocs

Nav

Python Language Services

parse

ast

function (source)
  • parse(source, filename='<unknown>', mode='exec', *, type_comments=False, feature_version=None, optimize=-1, module=None)
Parse the source into an AST node.
Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
Pass type_comments=True to get back type comments where the syntax allows.
Changed in 3.8, 3.13, 3.15
  • 3.8: Added type_comments, mode='func_type' and feature_version.
  • 3.13: The minimum supported version for feature_version is now (3, 7). The optimize argument was added.
  • 3.15: Added the module parameter.
1 Example
>>> print(ast.dump(ast.parse("""\
... async def f():
...     await other_func()
... """), indent=4))
Module(
    body=[
        AsyncFunctionDef(
            name='f',
            args=arguments(),
            body=[
                Expr(
                    value=Await(
                        value=Call(
                            func=Name(id='other_func'))))])])
from the Python docs
See Also
No see-alsos for ast/parse
0 Notes
No notes for parse