Code Monkey home page Code Monkey logo

Comments (4)

shea-parkes avatar shea-parkes commented on June 12, 2024

In case anyone else stumbles here someday, here's the code snippet of how we're handling this currently. Instead of dash.callback, we made mylib.callback and use it in the same way:

P = typing.ParamSpec("P")  # Params to dash.callback (e.g. dash.Outputs, dash.Inputs)
F = typing.TypeVar(  # Signature of our function being passed to dash.callback
    "F", bound=typing.Callable[..., typing.Any]
)

@functools.wraps(dash.callback)  # Just meta-fun, not the usage of `functools.wraps` I'm asking about...
def callback(
    *dash_io_args: P.args,
    **dash_io_kwargs: P.kwargs,
) -> typing.Callable[[F], F]:
    """wraps dash.callback to enable introspection to access the underlying function"""

    def our_decorator(f: F) -> F:
        """The inner closure that nests two decorators (functools.wraps and dash.callback)"""
        return functools.wraps(f)(dash.callback(*dash_io_args, **dash_io_kwargs)(f))

    return our_decorator

from dash.

shea-parkes avatar shea-parkes commented on June 12, 2024

Upon further review, it appears that the reason we didn't see a mycallback.__wrapped__ was that the callback wrapping functionality stores the wrapped function elsewhere, but then just returns back the original function from the decorator. I'm double checking, but I think that this means this could all be shut down. Sorry for the inconvenience.

from dash.

shea-parkes avatar shea-parkes commented on June 12, 2024

Indeed, dash.callback() returns the original function unaltered and unwrapped. It does create a wrapped version, but it stores that in its own internal ~namespace. So I'm closing this down. Sorry y'all.

from dash.

alexcjohnson avatar alexcjohnson commented on June 12, 2024

Thanks @shea-parkes - yes up to v2.3 we returned the wrapper but this was fixed in v2.4.0 via #1839

from dash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.