Skip to content

Improved static typing in dash.callback#3746

Open
odorikakeru wants to merge 6 commits intoplotly:devfrom
odorikakeru:baker/typed-callback
Open

Improved static typing in dash.callback#3746
odorikakeru wants to merge 6 commits intoplotly:devfrom
odorikakeru:baker/typed-callback

Conversation

@odorikakeru
Copy link
Copy Markdown

This PR improves static typing for the callback decorator by preserving wrapped function signatures in the callback decorator type contract.

Based on this conversation thread: [Feature Request] A "@dash.typed_callback" that plays more nicely with MyPy than "@dash.callback" #3691 - The decision was made to not implement @dash.typed_callback and instead update @dash.callback based on feedback.

Compliance tests added (not included in integration test directory as type hints don't affect run time behaviour).

DISCLOSURE: Testing code was written/edited with AI assistance.

Contributor Checklist

  • I have broken down my PR scope into the following TODO tasks
    • Update callback decorator type signature
    • Add and validate callback decorator typing/runtime tests (some testing code written with AI assistance)
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Plotly Dash community

@T4rk1n
Copy link
Copy Markdown
Contributor

T4rk1n commented Apr 16, 2026

This is looking good.

The new typing test file is not running on ci, the command needs to be adapted here:

pytest tests/compliance/test_typing.py

Also need to run npm run format and fix the failing pylint:

************* Module dash._callback
dash/_callback.py:14:0: C0413: Import "import flask" should be placed at the top of the module (wrong-import-position)
dash/_callback.py:16:0: C0413: Import "from .dependencies import handle_callback_args, handle_grouped_callback_args, Output, ClientsideFunction, Input" should be placed at the top of the module (wrong-import-position)
dash/_callback.py:23:0: C0413: Import "from .development.base_component import ComponentRegistry" should be placed at the top of the module (wrong-import-position)
dash/_callback.py:24:0: C0413: Import "from .exceptions import InvalidCallbackReturnValue, PreventUpdate, WildcardInLongCallback, MissingLongCallbackManagerError, BackgroundCallbackError, ImportedInsideCallbackError" should be placed at the top of the module (wrong-import-position)
dash/_callback.py:33:0: C0413: Import "from ._grouping import flatten_grouping, make_grouping_by_index, grouping_len" should be placed at the top of the module (wrong-import-position)
dash/_callback.py:38:0: C0413: Import "from ._utils import create_callback_id, stringify_id, to_json, coerce_to_list, AttributeDict, clean_property_name" should be placed at the top of the module (wrong-import-position)
dash/_callback.py:47:0: C0413: Import "from . import _validate" should be placed at the top of the module (wrong-import-position)
dash/_callback.py:48:0: C0413: Import "from .background_callback.managers import BaseBackgroundCallbackManager" should be placed at the top of the module (wrong-import-position)
dash/_callback.py:49:0: C0413: Import "from ._callback_context import context_value" should be placed at the top of the module (wrong-import-position)
dash/_callback.py:50:0: C0413: Import "from ._no_update import NoUpdate" should be placed at the top of the module (wrong-import-position)

-----------------------------------
Your code has been rated at 9.98/10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants