fix(py-parser): read docstring Args descriptions for async def main

Merged
RU
4d ago
+42-10

Summary

For a Python script whose entrypoint is async def main, the argument descriptions written in the docstring's Args: section were dropped from the inferred schema, while a plain def main got them. Redo of #12471 (thanks @hsusul).

Changes

  • filter_relevant_statements also keeps top-level async def blocks, so they reach the AST pass.
  • extract_code_metadata reads the docstring of main whether or not it is async.
  • When the line-based prefilter produces code that doesn't parse (a column-0 line inside a triple-quoted string, such as inline SQL, ends the block early), the metadata pass parses the full source instead of returning no metadata. Without this, keeping async def blocks would have made such scripts lose their enum choices and defaults.
  • Regression test: async def main with an enum argument, an Args: docstring and a column-0 multiline string keeps its description, enum choices and default.

Test plan

  • cargo test in backend/parsers/windmill-parser-py (37 passed)
  • New test fails on main and fails without the fallback; passes with both changes

šŸ¤– Generated with Claude Code