|
35 | 35 | from .processor import ( |
36 | 36 | _resolve_t_attrs as resolve_dynamic_attrs, |
37 | 37 | _resolve_html_attrs as coerce_to_html_attrs, |
38 | | - _kebab_to_snake, |
39 | 38 | HasHTMLDunder, |
40 | 39 | AttributesDict, |
| 40 | + _prep_component_kwargs, |
41 | 41 | ) |
42 | 42 | from .callables import get_callable_info |
43 | 43 |
|
@@ -134,45 +134,6 @@ def interpolate_attrs( |
134 | 134 | bf.append(attrs_str) |
135 | 135 |
|
136 | 136 |
|
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 | | - |
176 | 137 | type InterpolateComponentInfo = tuple[str, Sequence[TAttribute], int, int | None, int] |
177 | 138 |
|
178 | 139 |
|
@@ -211,7 +172,8 @@ def interpolate_component( |
211 | 172 | children=children_template # @DESIGN: children_struct=children_struct_t ? |
212 | 173 | ) |
213 | 174 | # @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) |
215 | 177 | res = component_callable(**kwargs) |
216 | 178 | # @DESIGN: Determine return signature via runtime inspection? |
217 | 179 | if isinstance(res, tuple): |
|
0 commit comments