You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python SDK: AST-based module analysis misses several Python patterns #13097
In v0.20.7 (#11803) we changed how the Python SDK reads your module to register it with the engine. The old way ran your code; the new way reads it as text only. Reading text instead of running code is the right long-term move — it unlocks a feature called "self calls" — but the new reader doesn't yet recognise everything Python can express.
That means modules that worked fine in v0.20.6 may now register the wrong types or skip parts of the schema in v0.20.7 and later.
Symptoms users have hit
A function disappears from dagger functions because we wrote it in a way the new reader didn't recognise — for example, importing the dagger package under a different name (import dagger as d), or inheriting a function from a base class.
A type ends up wrong in the schema — for example, a parameter that should accept a directory shows up as some other kind of value, or its default is silently dropped.
Three follow-up PRs already shipped fixes for the most common shapes:
Then a wider audit (#13095) catalogued many more shapes that still misbehave and fixes them, plus adds a differential test suite that compares the new reader's output against the old run-the-code path so the two stay in sync going forward.
As discussed, one approach could be to integrate the CPython's Lib/test/test_typing.py suite into our static analysis port (maybe others?)?
As the previous runtime path relied on CPython's typing.get_type_hints() function, we can be sure that the contract upon which people were writing their Python Dagger SDK functions is the contract that these test coverage should support
Another question: what about the different Python versions, as typing.get_type_hints() is dependent on the Python version ? How does our Typescript SDK static analysis handle that 👀 ?
Differential testing — for any Python source, run the AST analyzer and a runtime introspector backed by typing.get_type_hints, then assert the two outputs match. Pattern coverage is informed by test_typing.py, but every test directly checks the contract you described.
Property-based testing with Hypothesis — generates random combinations of supported shapes and runs the same diff. Catches combinations no fixture lists.
Real-world corpus — runs the diff against every Python module in telchak/daggerverse (18 modules). All pass.
That should gives us a similar guarantee than test_typing.py but only for what Dagger supports
Regaring the property based testing, this is what it looks like. Instead of writing one fixture per pattern by hand, we describe the shape of valid inputs and let Hypothesis generate them.
# A small grammar of what a Dagger module parameter can look like.@compositedefparameter(draw):
base=draw(sampled_from(["str", "int", "bool",
"dagger.Directory", "dagger.Container"]))
ifdraw(booleans()):
base=f"Optional[{base}]"# wrap in Optional[…]ifdraw(booleans()):
meta=draw(sampled_from(['Doc("hi")', 'Name("alt")',
'DefaultPath(".")']))
base=f"Annotated[{base}, {meta}]"# wrap in Annotated[…]returnbase@given(annotation=parameter())deftest_ast_matches_runtime(annotation):
source=f""" import dagger from typing import Annotated, Optional from dagger import Doc, Name, DefaultPath @dagger.object_type class Foo: @dagger.function def f(self, x: {annotation}) -> str: ... """ast_md=analyze_source_string(source, "Foo") # static analysisruntime_md=runtime_introspect(source, "Foo") # typing.get_type_hintsassert_metadata_equivalent(ast_md, runtime_md)
Hypothesis then runs this dozens or hundreds of times with combinations like:
Regarding the different python versions, I'll see to use the matrix of python versions we already supports. Or to extend them in some way, but we already run all our tests against 5 different python versions.
Activity
grouville commentedon May 5, 2026
As discussed, one approach could be to integrate the CPython's Lib/test/test_typing.py suite into our static analysis port (maybe others?)?
As the previous runtime path relied on CPython's
typing.get_type_hints()function, we can be sure that the contract upon which people were writing their Python Dagger SDK functions is the contract that these test coverage should supportgrouville commentedon May 5, 2026
Another question: what about the different Python versions, as
typing.get_type_hints()is dependent on the Python version ? How does our Typescript SDK static analysis handle that 👀 ?eunomie commentedon May 5, 2026
We can't directly integrate
test_typing.py, it's not testing the same thing (it's testing the runtime, and many things we don't care about.For now #13095 is doing:
That should gives us a similar guarantee than test_typing.py but only for what Dagger supports
eunomie commentedon May 5, 2026
Regaring the property based testing, this is what it looks like. Instead of writing one fixture per pattern by hand, we describe the shape of valid inputs and let Hypothesis generate them.
Hypothesis then runs this dozens or hundreds of times with combinations like:
Optional[Annotated[dagger.Directory, DefaultPath(".")]]Annotated[int, Doc("hi"), Name("alt")]dagger.ContainerOptional[bool]It already finds some issues.
Regarding the different python versions, I'll see to use the matrix of python versions we already supports. Or to extend them in some way, but we already run all our tests against 5 different python versions.