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

Home Page:https://www.dash-extensions.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type hinting for Serverside

Kuhlwein opened this issue · comments

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)