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

Make Serverside generic #274

Closed Kuhlwein closed 1 year ago

Kuhlwein commented 1 year ago

Make serverside generic in order to support better type hinting.

Solves #272

codecov-commenter commented 1 year ago

Codecov Report

Merging #274 (1f42670) into master (2bf9f45) will increase coverage by 0.01%. The diff coverage is 100.00%.

:exclamation: Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master     #274      +/-   ##
==========================================
+ Coverage   84.12%   84.14%   +0.01%     
==========================================
  Files           9        9              
  Lines         945      946       +1     
==========================================
+ Hits          795      796       +1     
  Misses        150      150              
Impacted Files Coverage Δ
dash_extensions/enrich.py 82.12% <100.00%> (+0.02%) :arrow_up:
emilhe commented 1 year ago

Could you add a small example demonstrating how the new functionality is used?

Kuhlwein commented 1 year ago

Sure, you can use it as described on the related issue, for instance:

@callback(
    Output("some-output", "data"),
    Input("some-input", "value")
)
def foo(bar: str) -> Serverside[str]:
    return Serverside(bar)

It is of course still possible to omit the square brackets since Serverside defaults to Serverside[Any].

emilhe commented 1 year ago

I like this approach. One note is that in some cases, the return may not always be saved server side. But I guess in that case, one would just use a typehint of the form Union[str, Serverside[str]].