Skip to content

[Feature Request] A "@dash.typed_callback" that plays more nicely with MyPy than "@dash.callback" #3691

@odorikakeru

Description

@odorikakeru

What I Want
The projects I work on include MyPy in the testing pipeline. For "quality of life" and code readability reasons I am on a mission to reduce the need for `# type: ignore" style comments as much as possible

Proposed Solution
In my current project I am using the following wrapper:

Params = ParamSpec('Params')
ReturnVar = TypeVar('ReturnVar')
Func = Callable[Params, ReturnVar]

def typed_callback(app: Dash, *args: Any, **kwargs: Any) -> Callable[[Func], Func]:
    return cast(Callable[[Func], Func], app.callback(*args, **kwargs))

I have forked the dev branch and added a typed_callback function (here: _callback.py) as a proof of concept.

I would like feedback on this idea.

(Disclosure: the tests in my fork were generated using AI)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions