ast_harvest¶
- ast_harvest(source: str) ASTSymbols[source]¶
Parse source and return structural metadata without executing any code.
This is the main entry point for the AST pre-pass stage. A fresh
ASTHarvesteris created for each call, making this function fully re-entrant.- Parameters:
source (str) – Raw Python source text.
- Returns:
ASTSymbols – Populated container of all harvested metadata. On a
SyntaxErrorthe result will be empty but valid — no exception is raised.
Examples
>>> syms = ast_harvest("") >>> syms.classes [] >>> syms = ast_harvest("class Foo(Bar): pass") >>> syms.classes[0].name, syms.classes[0].bases ('Foo', ['Bar']) >>> syms = ast_harvest("async def fetch(url: str) -> None: ...") >>> fn = syms.functions[0] >>> fn.is_async, fn.name (True, 'fetch') >>> syms = ast_harvest("X = TypeVar('X')") >>> syms.typevar_decls[0].kind 'TypeVar'
See also
Public API reference — overview of all public names.