fix(backend): handle async functions in AST parsing utilities - #892
fix(backend): handle async functions in AST parsing utilities#892harshhh817 wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Friendly ping — small backend fix: Regression tests included; still green. Happy to rebase onto current main if that helps. |
astutils only checked ast.FunctionDef, so async def helpers were mishandled: parse_functions dropped them, get_function_and_class_names did not register their names, and get_marshal_candidates walked into their bodies -- leaking the function's local variables as marshal candidates while missing the function name itself. Treat ast.AsyncFunctionDef the same as ast.FunctionDef in all three, so an async def in a functions/step cell is parsed, its name recognised, and its locals no longer leak between steps. Add regression tests. Signed-off-by: Harsh Gupta <harshgupta93198@gmail.com>
a80ce93 to
4193cc4
Compare
What this does
Treats
ast.AsyncFunctionDefthe same asast.FunctionDefinkale/common/astutils.py, soasync defhelpers in afunctions/stepcell are handled correctly by:parse_functions— now extracts async functions (previously dropped them).get_function_and_class_names— now registers async function names.get_marshal_candidates— now stops at async function bodies, so it no longer leaks their local variables and correctly adds the function name.Why
astutilsonly checkedast.FunctionDef, so anasync defwas mishandled in three ways. Reproducer onmain:The
get_marshal_candidatescase is the most harmful: it walked into the async function body and returned the function's local variable as a marshal candidate while missing the function name. In a pipeline this means anasync defhelper would not be injected into steps, would be treated as a missing dependency, and its internals could be marshalled between steps.Testing
Extended
kale/tests/unit_tests/test_ast.pywith an async snippet and a dedicatedparse_functionsasync test. All three new assertions fail onmainand pass with this change; the fulltest_ast.pysuite (47 tests) passes.I came across this while working on the output-artifact/AST code in #874. Happy to open a tracking issue if maintainers prefer.