Type hinting for Serverside
Kuhlwein opened this issue · comments
Morten Kuhlwein commented
The recent update to the way ServersideOutput works is restricting the use of type hinting. Previously it was possible to do something like this:
@callback(
ServersideOutput("some-output", "data"),
Input("some-input", "value")
)
def foo(bar: str) -> str:
return bar
The new way to make this callback would be something like this:
@callback(
Output("some-output", "data"),
Input("some-input", "value")
)
def foo(bar: str) -> Serverside:
return Serverside(bar)
You can no longer tell from the function signature that it is returning a string, and static type checkers won't catch it if something different is returned. A possible solution could be to make Serverside generic such that the following would be possible:
@callback(
Output("some-output", "data"),
Input("some-input", "value")
)
def foo(bar: str) -> Serverside[str]:
return Serverside(bar)