emilhe / dash-extensions

The dash-extensions package is a collection of utility functions, syntax extensions, and Dash components that aim to improve the Dash development experience
https://www.dash-extensions.com/
MIT License
409 stars 58 forks source link

Type hinting for Serverside #272

Closed Kuhlwein closed 1 year ago

Kuhlwein commented 1 year ago

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)