Skip to content

Commit c7c3b6a

Browse files
fix: calling after a 'subscript' trigger a warning when validating hooks
1 parent 3b0adff commit c7c3b6a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

solara/validate_hooks.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,12 @@ def visit_Call(self, node: ast.Call):
142142
if isinstance(func, ast.Call):
143143
# Nested function, it will appear in another node later
144144
return
145+
id_ = None
145146
if isinstance(func, ast.Name):
146147
id_ = func.id
147148
elif isinstance(func, ast.Attribute):
148149
id_ = func.attr
149-
else:
150-
warnings.warn(f"Unexpected function node type: {func}, line={node.lineno}")
151-
return
152-
if self.matches_use_function(id_):
150+
if id_ is not None and self.matches_use_function(id_):
153151
self.error_on_early_return(node, id_)
154152
self.error_on_invalid_scope(node, id_)
155153
self.generic_visit(node)

tests/unit/hook_use_invalid_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ def Page3(): # noqa: SH103
7070
solara.Text("Done")
7171

7272

73+
def test_hook_validate_ast_checks():
74+
# a Call on a Subscript failed
75+
@solara.component
76+
def Page4():
77+
funcs = [lambda x: x]
78+
funcs[0](1)
79+
80+
7381
def test_hook_use_invalid_conditional():
7482
with hook_check_warn(), pytest.warns(UserWarning):
7583

0 commit comments

Comments
 (0)