Skip to content

chore(sdk/python): remove AST-based module analyzer - #13251

Merged
sipsma merged 2 commits into
dagger:mainfrom
eunomie:rm-python-ast
May 28, 2026
Merged

sipsma merged 2 commits into
dagger:mainfrom
eunomie:rm-python-ast

Conversation

@eunomie

@eunomie eunomie commented May 28, 2026

Copy link
Copy Markdown
Member

Summary

  • Remove the AST-based module analyzer (introduced in feat(sdk/python): AST based analysis to introspect #11803) and revert Python module registration to runtime introspection (import + typing.get_type_hints).
  • Delete the _analyzer package, _discovery.py, and the AST-specific test suite; drop the hypothesis dev dependency and its pytest options.
  • Restore the runtime _typedefs/register path. Return types are str (the ModuleID scalar was removed by dagql: native interfaces, unified IDs #12041's unified IDs), avoiding an import-time crash on Python 3.10–3.13.

Test plan

  • ruff check + ruff format --check pass
  • Python unit tests pass across 3.10–3.14

Revert module registration to runtime introspection, removing the
AST-based analyzer added in dagger#11803 along with its tests and the
hypothesis dev dependency. Registration imports the module and derives
type definitions via typing.get_type_hints, as it did before the
analyzer landed.

Signed-off-by: Yves Brissaud <[email protected]>
@eunomie
eunomie requested a review from a team as a code owner May 28, 2026 15:11
@eunomie eunomie added this to the v0.21.1 milestone May 28, 2026
Signed-off-by: Yves Brissaud <[email protected]>
@eunomie
eunomie requested review from a team as code owners May 28, 2026 15:46

@marcosnils marcosnils left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving since this is a revert and all the tests are passing.

@sipsma
sipsma merged commit 12d1b08 into dagger:main May 28, 2026
78 checks passed
@danielgafni

danielgafni commented May 29, 2026 •

Copy link
Copy Markdown

What happened, why did you decide to revert it? Just curious

@eunomie

eunomie commented May 29, 2026

Copy link
Copy Markdown
Member Author

What happened, why did you decide to revert it? Just curious

Very good question. I'll also put something on the python discord channel.

So my main driver is performances of the SDKs, including the python one.
And by performances, what I want to improve is the user experience when calling a function (not when developing functions, that's a separate topic). Python is doing a lot of things at runtime, so my initial goal was to remove as much as possible all the dynamic aspects at runtime. The AST was a solution in that direction, by allowing to analyse the code before to load anything.
And regarding performances (and code analysis) there's also the question of self calls. Currently they add a penalty at runtime as we need a double analysis/codegen (codegen of the base types, analyse the module code, then re-codegen of all the types including the module itself, then analysis again because that's at runtime). By running an AST it should fix that.

But the current situation is it didn't worked as nice as I was hoping. Since I introduced it, each time we are making a release we are finding new edge cases that are not covered. That's a pain by itself, extra work, outside of the actual focus on workspace/1.0, new releases. That's a pain for the users, modules that was working before the AST starts to not work. But there's also a bigger issue, the current AST based analysis can't find all the things people are doing in python. Some can be solved at the price of breaking changes, some can't be fixed currently, by design.

From there, multiple options:

  1. continue trying to fix the AST
  2. try to use different libraries to have a better AST, for instance jedi
  3. revert to the previous type of analysis

I picked the third, to rollback, but with something else in mind: during all the work on the AST, we started to plan some other changes on the SDK side, and one of them is to remove all codegen from the runtime phase, to keep it only for the develop phase (using generate). This is kind of orthogonal with the question of AST analysis or not, but there's something interesting there: by pushing the codegen out of runtime, it means it solves (part of) the performances issues by design and it will bring self calls at no extra runtime cost. There will still have some dynamic aspects I'd like to remove from the runtime. But it will be better for sure.

And as it's orthogonal, I can revisit later the question of the AST, based on different libraries. This design change will gives us more time to do that as performances will already be better.

@danielgafni

danielgafni commented May 29, 2026 •

Copy link
Copy Markdown

@eunomie

eunomie commented May 29, 2026

Copy link
Copy Markdown
Member Author

I haven't, but that might be interesting to also give a try, thanks for the suggestion.

social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
dagger 0.21.1

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## v0.21.1 - 2026-05-29

### Added
- Add native GraphQL interfaces and unified object IDs in DagQL by @vito in dagger/dagger#12041 \
  Dagger now exposes objects through the standard `Node` interface and `ID` scalar, enabling APIs to accept generic Dagger objects while preserving SDK compatibility through legacy `FooID` and `loadFooFromID` views for older clients.

### Fixed
- Python SDK: fix unhandled module registration cases and bugs by removing the AST-based module analyzer and returning to runtime introspection by @eunomie in dagger/dagger#13251
- Fix Go module generation to avoid unnecessary dependency churn in generated `go.mod` and `go.sum` files by @sipsma in dagger/dagger#13244
- Fix registry authentication so `withRegistryAuth` credentials are not incorrectly skipped and authenticated publishes keep working after anonymous pulls to the same registry by @marcosnils + @sipsma in dagger/dagger#13255 dagger/dagger#13256
- Fix published image layer structure so `withDirectory` and `withFile` operations preserve expected layer boundaries instead of being squashed into a few large layers by @sipsma in dagger/dagger#13242
- Fix Dockerfile `RUN --mount=type=bind` conversion when the bind source selector points to a regular file, improving compatibility with file and directory bind mounts by @sipsma in dagger/dagger#13273
- Fix module source cache dependency retention, including ephemeral `missing shared result` errors after cache persistence or engine restarts by @sipsma in dagger/dagger#13243
- Fix a bug where some cache entries did not have their size calculated during background and shutdown pruning by @sipsma in dagger/dagger#13225
- Fix repeated `op://` 1Password secret reads by caching resolved 1Password secret values during a run, avoiding provider rate limits when the same secret is mounted or read multiple times by @matipan in dagger/dagger#13249
- Fix Windows Changeset exports so `RemovePaths` entries cannot remove files outside the selected export root through backslash or absolute-path interpretation by @marcosnils in dagger/dagger#13222
- Fix `dagger --x-release` for tagged releases so semver refs download release artifacts instead of looking in the main-build artifact namespace, and prevent local runner override environment from leaking into the re-executed CLI by @grouville in dagger/dagger#13259

### What to do next?
- Read the [documentation](https://docs.dagger.io)
- Join our [Discord server](https://discord.gg/dagger-io)
- Follow us on [Twitter](https://twitter.com/dagger_io)

</pre>
  <p>View the full release notes at <a href="https://github.com/dagger/dagger/releases/tag/v0.21.1">https://github.com/dagger/dagger/releases/tag/v0.21.1</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!9585
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants