Skip to content

Commit 9d99422

Browse files
Use processor component kwargs prep.
1 parent 7307024 commit 9d99422

File tree

1 file changed

+3
-41
lines changed

1 file changed

+3
-41
lines changed

tdom/transformer.py

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
from .processor import (
3636
_resolve_t_attrs as resolve_dynamic_attrs,
3737
_resolve_html_attrs as coerce_to_html_attrs,
38-
_kebab_to_snake,
3938
HasHTMLDunder,
4039
AttributesDict,
40+
_prep_component_kwargs,
4141
)
4242
from .callables import get_callable_info
4343

@@ -134,45 +134,6 @@ def interpolate_attrs(
134134
bf.append(attrs_str)
135135

136136

137-
def _prep_cinfo(
138-
component_callable: Callable, attrs: AttributesDict, system: dict[str, object]
139-
):
140-
# @DESIGN: This is lifted from the processor and then grossified.
141-
# Not sure this will work out but maybe we'd unify these.
142-
callable_info = get_callable_info(component_callable)
143-
144-
if callable_info.requires_positional:
145-
raise TypeError(
146-
"Component callables cannot have required positional arguments."
147-
)
148-
149-
kwargs: AttributesDict = {}
150-
151-
# Inject system kwargs first.
152-
if system:
153-
if callable_info.kwargs:
154-
kwargs.update(system)
155-
else:
156-
for kw in system:
157-
if kw in callable_info.named_params:
158-
kwargs[kw] = system[kw]
159-
160-
# Plaster attributes in over top of system kwargs.
161-
for attr_name, attr_value in attrs.items():
162-
snake_name = _kebab_to_snake(attr_name)
163-
if snake_name in callable_info.named_params or callable_info.kwargs:
164-
kwargs[snake_name] = attr_value
165-
166-
# Check to make sure we've fully satisfied the callable's requirements
167-
missing = callable_info.required_named_params - kwargs.keys()
168-
if missing:
169-
raise TypeError(
170-
f"Missing required parameters for component: {', '.join(missing)}"
171-
)
172-
173-
return kwargs
174-
175-
176137
type InterpolateComponentInfo = tuple[str, Sequence[TAttribute], int, int | None, int]
177138

178139

@@ -211,7 +172,8 @@ def interpolate_component(
211172
children=children_template # @DESIGN: children_struct=children_struct_t ?
212173
)
213174
# @DESIGN: Determine return signature from callable info (cached inspection) ?
214-
kwargs = _prep_cinfo(component_callable, resolved_attrs, system_dict)
175+
callable_info = get_callable_info(component_callable)
176+
kwargs = _prep_component_kwargs(callable_info, resolved_attrs, system=system_dict)
215177
res = component_callable(**kwargs)
216178
# @DESIGN: Determine return signature via runtime inspection?
217179
if isinstance(res, tuple):

0 commit comments

Comments
 (0)