3636 'pricingModel' : 'pricing_model' ,
3737}
3838
39- # Seed models for the TypedDict pruning. Every TypedDict in `_typeddicts.py` that is not
40- # transitively reachable from this set is removed. Keep in sync with the `dict | <Model>` unions
41- # on resource-client method signatures.
42- TYPEDDICT_SEEDS : frozenset [str ] = frozenset (
39+ # TypedDicts accepted as inputs by resource-client methods. These are the roots of the reachability
40+ # walk over `_typeddicts_generated.py`: anything not reachable from here (directly or transitively)
41+ # is dropped so only the TypedDicts that are part of the public input surface — plus their nested
42+ # shapes — survive. Names are the raw datamodel-codegen outputs (no `Dict` suffix yet); the suffix
43+ # is added later by `rename_with_dict_suffix`. Update this set whenever a new `<Name>Dict | <Name>`
44+ # union is introduced on a resource-client method signature.
45+ RESOURCE_INPUT_TYPEDDICTS : frozenset [str ] = frozenset (
4346 {
44- 'Request' ,
45- 'TaskInput' ,
46- 'WebhookCreate' ,
47+ 'Request' , # RequestQueueClient.update_request
48+ 'TaskInput' , # Actor/Task start/call/update default input
49+ 'WebhookCreate' , # Actor/Task start/call webhook list element
4750 }
4851)
4952
@@ -191,17 +194,17 @@ def _collect_name_references(node: ast.AST, exclude: set[str]) -> set[str]:
191194 return refs - exclude
192195
193196
194- def _compute_transitive_closure (deps : dict [str , set [str ]], seeds : set [str ]) -> set [str ]:
195- """Return every symbol transitively reachable from any seed."""
196- closure : set [str ] = set ()
197+ def _compute_reachable_symbols (deps : dict [str , set [str ]], seeds : set [str ]) -> set [str ]:
198+ """Return every symbol transitively reachable from any seed via `deps` ."""
199+ reachable : set [str ] = set ()
197200 stack = [s for s in seeds if s in deps ]
198201 while stack :
199202 name = stack .pop ()
200- if name in closure :
203+ if name in reachable :
201204 continue
202- closure .add (name )
203- stack .extend (ref for ref in deps [name ] if ref in deps and ref not in closure )
204- return closure
205+ reachable .add (name )
206+ stack .extend (ref for ref in deps [name ] if ref in deps and ref not in reachable )
207+ return reachable
205208
206209
207210def prune_typeddicts (content : str , seeds : frozenset [str ]) -> tuple [str , set [str ]]:
@@ -218,7 +221,7 @@ def prune_typeddicts(content: str, seeds: frozenset[str]) -> tuple[str, set[str]
218221 # Ignore builtins and imported names — we only care about cross-references within the file.
219222 deps [name ] = _collect_name_references (node , exclude = {name }) & symbol_names
220223
221- kept = _compute_transitive_closure (deps , set (seeds ))
224+ kept = _compute_reachable_symbols (deps , set (seeds ))
222225
223226 missing_seeds = seeds - symbol_names
224227 if missing_seeds :
@@ -265,7 +268,7 @@ def postprocess_models(path: Path) -> bool:
265268def postprocess_typeddicts (path : Path ) -> bool :
266269 """Apply `_typeddicts_generated.py`-specific fixes. Returns True if the file changed."""
267270 original = path .read_text ()
268- pruned , kept = prune_typeddicts (original , TYPEDDICT_SEEDS )
271+ pruned , kept = prune_typeddicts (original , RESOURCE_INPUT_TYPEDDICTS )
269272 renamed = rename_with_dict_suffix (pruned , kept )
270273 flattened = flatten_empty_typeddicts (renamed )
271274 final = add_docs_group_decorators (flattened , 'Typed dicts' )
0 commit comments