Skip to content

Commit a6efb85

Browse files
authored
Fix missing type hints for @content_component (#1146)
Closes #912
1 parent a53a70d commit a6efb85

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

mesop/component_helpers/helper.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
Any,
99
Callable,
1010
Generator,
11+
Generic,
1112
KeysView,
13+
ParamSpec,
1214
Type,
1315
TypeVar,
1416
cast,
@@ -66,8 +68,12 @@ def slot():
6668
runtime().context().save_current_node_as_slot()
6769

6870

69-
class _UserCompositeComponent:
70-
def __init__(self, fn: Callable[..., Any]):
71+
T = TypeVar("T")
72+
P = ParamSpec("P")
73+
74+
75+
class _UserCompositeComponent(Generic[T]):
76+
def __init__(self, fn: Callable[[], T]):
7177
self.prev_current_node = runtime().context().current_node()
7278
fn()
7379
node_slot = runtime().context().node_slot()
@@ -93,9 +99,11 @@ def __exit__(self, exc_type, exc_val, exc_tb): # type: ignore
9399
runtime().context().set_current_node(self.prev_current_node)
94100

95101

96-
def content_component(fn: Callable[..., Any]):
102+
def content_component(
103+
fn: Callable[P, T],
104+
) -> Callable[P, _UserCompositeComponent[T]]:
97105
@wraps(fn)
98-
def wrapper(*args: Any, **kwargs: Any):
106+
def wrapper(*args: P.args, **kwargs: P.kwargs) -> _UserCompositeComponent[T]:
99107
return _UserCompositeComponent(lambda: fn(*args, **kwargs))
100108

101109
return wrapper

0 commit comments

Comments
 (0)