Skip to content

Commit 1499bc4

Browse files
committed
Fix python outputs dyn table code generation
1 parent 1866f4c commit 1499bc4

2 files changed

Lines changed: 20 additions & 17 deletions

File tree

src/styx/backend/generic/languageprovider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def dyn_declare(self, lookup: SymbolLUT, union: ir.Param[ir.Param.StructUnion])
466466
...
467467

468468
@abstractmethod
469-
def param_dict_type_declare(self, lookup: SymbolLUT, struct: ir.Param[ir.Param.Struct]) -> LineBuffer:
469+
def param_dict_type_declare(self, lut: SymbolLUT, struct: ir.Param[ir.Param.Struct]) -> LineBuffer:
470470
"""Declare the type a subcommand parameter dictionary."""
471471
...
472472

src/styx/backend/python/languageprovider.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -685,26 +685,28 @@ def dyn_declare(self, lut: SymbolLUT, union: ir.Param[ir.Param.StructUnion]) ->
685685
for s in union.body.alts
686686
if s.has_outputs_deep()
687687
]
688-
func_get_build_outputs = GenericFunc(
689-
name=lut.fn_dyn_union_fn_struct_make_outputs[union.base.id_],
690-
return_type="typing.Any",
691-
docstring_body="Get build outputs function by command type.",
692-
return_descr="Build outputs function.",
693-
args=[
694-
GenericArg(
695-
name="t",
696-
docstring="Command type",
697-
type="str",
698-
)
699-
],
700-
body=["return {", *indent([f"{key}: {value}," for key, value in items]), "}.get(t)"],
701-
)
688+
func_get_build_outputs = None
689+
if len(items):
690+
func_get_build_outputs = GenericFunc(
691+
name=lut.fn_dyn_union_fn_struct_make_outputs[union.base.id_],
692+
return_type="typing.Any",
693+
docstring_body="Get build outputs function by command type.",
694+
return_descr="Build outputs function.",
695+
args=[
696+
GenericArg(
697+
name="t",
698+
docstring="Command type",
699+
type="str",
700+
)
701+
],
702+
body=["return {", *indent([f"{key}: {value}," for key, value in items]), "}.get(t)"],
703+
)
702704

703705
# Validate params function lookup
704706
items = [
705707
(self.expr_str(s.body.public_name), lut.fn_struct_validate_params[s.base.id_]) for s in union.body.alts
706708
]
707-
func_get_build_outputs = GenericFunc(
709+
func_struct_validate_params = GenericFunc(
708710
name=lut.fn_dyn_union_fn_struct_validate_params[union.base.id_],
709711
return_type="typing.Any",
710712
docstring_body="Get validate params function by command type.",
@@ -721,7 +723,8 @@ def dyn_declare(self, lut: SymbolLUT, union: ir.Param[ir.Param.StructUnion]) ->
721723

722724
return [
723725
func_get_build_cargs,
724-
func_get_build_outputs,
726+
*([func_get_build_outputs] if func_get_build_outputs else []),
727+
func_struct_validate_params,
725728
]
726729

727730
def _make_typed_dict(self, symbol: ExprType, items: list[tuple[ExprType, ExprType]]) -> LineBuffer:

0 commit comments

Comments
 (0)