Skip to content

Commit 788c14d

Browse files
committed
Minor cleanups
1 parent a0e696c commit 788c14d

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

tdom/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class TComponent(TNode):
100100
start_i_index: int
101101
"""The interpolation index for the component's starting tag name."""
102102

103-
end_i_index: int = -1
103+
end_i_index: int | None = None
104104
"""The interpolation index for the component's ending tag name, if any."""
105105

106106
attrs: list[TAttribute] = field(default_factory=list)

tdom/processor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def _resolve_t_attrs(
170170
for sub_k, sub_v in _substitute_spread_attrs(spread_value):
171171
new_attrs[sub_k] = sub_v
172172
case _:
173-
assert False, f"Unknown TAttribute type: {type(attr).__name__}"
173+
raise ValueError(f"Unknown TAttribute type: {type(attr).__name__}")
174174
return new_attrs
175175

176176

@@ -384,7 +384,7 @@ def _resolve_t_node(t_node: TNode, interpolations: tuple[Interpolation, ...]) ->
384384
):
385385
start_interpolation = interpolations[start_i_index]
386386
end_interpolation = (
387-
interpolations[end_i_index] if end_i_index != -1 else None
387+
None if end_i_index is None else interpolations[end_i_index]
388388
)
389389
resolved_attrs = _resolve_t_attrs(t_attrs, interpolations)
390390
resolved_children = _substitute_and_flatten_children(
@@ -396,14 +396,14 @@ def _resolve_t_node(t_node: TNode, interpolations: tuple[Interpolation, ...]) ->
396396
end_interpolation is not None
397397
and end_interpolation.value != start_interpolation.value
398398
):
399-
raise ValueError("Mismatched component start and end callables.")
399+
raise TypeError("Mismatched component start and end callables.")
400400
return _invoke_component(
401401
attrs=resolved_attrs,
402402
children=resolved_children,
403403
interpolation=start_interpolation,
404404
)
405405
case _:
406-
assert False, f"Unknown TNode type: {type(t_node).__name__}"
406+
raise ValueError(f"Unknown TNode type: {type(t_node).__name__}")
407407

408408

409409
# --------------------------------------------------------------------------

tdom/processor_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,3 +1138,10 @@ def RequiresPositional(whoops: int, /) -> Template: # pragma: no cover
11381138
def test_component_requiring_positional_arg_fails():
11391139
with pytest.raises(TypeError):
11401140
_ = html(t"<{RequiresPositional} />")
1141+
1142+
1143+
def test_mismatched_component_closing_tag_fails():
1144+
with pytest.raises(TypeError):
1145+
_ = html(
1146+
t"<{FunctionComponent} first=1 second={99} third-arg='comp1'>Hello</{ClassComponent}>"
1147+
)

0 commit comments

Comments
 (0)