Skip to content

[BUG] Remaining Typing/Mypy errors after Dash 3.0.2 to Dash 3.0.4 upgrade #3292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ghaarsma opened this issue Apr 26, 2025 · 2 comments
Open
Assignees
Labels
bug something broken P2 considered for next cycle

Comments

@ghaarsma
Copy link

The following minimum example:

from typing import Any

from dash import Dash, html, dash_table, dcc

app = Dash()

app.layout = html.Div(
    [
        html.H3("Initial Title", id="my-title"),
        html.Div(
            dash_table.DataTable(
                id="table",
                columns=[
                    {"name": "Type", "id": "Type"},
                    {"name": "Processed", "id": "Processed"},
                    {"name": "Start", "id": "Start"},
                    {"name": "End", "id": "End"},
                ],
                style_cell={"textAlign": "left"},
                filter_action="native",
                sort_action="native",
            ),
        ),
    ],
    className="topmenu",
    role="button",
    **{"aria-pressed": "false"},
)


class MyGraph(dcc.Graph):
    """Subclass of dash_core_components.Graph to remove modeBarButtons"""

    def __init__(self, *args: Any, **kwargs: Any) -> None:
        super().__init__(
            *args,
            **kwargs,
            config=dict(modeBarButtonsToRemove=["sendDataToCloud"]),
        )

Generates no issues with mypy 1.15.0 and Dash 3.0.2. Then upgrading to Dash 3.0.4

(venv) PS C:\Users\gxvh\Python\dash_mypy> mypy
Success: no issues found in 1 source file
(venv) PS C:\Users\gxvh\Python\dash_mypy> poetry update
Updating dependencies
Resolving dependencies... (54.3s)

Package operations: 0 installs, 1 update, 0 removals

  - Updating dash (3.0.2 -> 3.0.4)

Writing lock file
(venv) PS C:\Users\gxvh\Python\dash_mypy> mypy
dash_test.py:11: error: Module has no attribute "DataTable"  [attr-defined]
dash_test.py:27: error: Argument 4 to "Div" has incompatible type "**dict[str, str]"; expected "SupportsFloat | SupportsInt | SupportsComplex | None"  [arg-type]
dash_test.py:27: error: Argument 4 to "Div" has incompatible type "**dict[str, str]"; expected "bool | None"  [arg-type]
dash_test.py:27: error: Argument 4 to "Div" has incompatible type "**dict[str, str]"; expected "Literal['hidden', 'HIDDEN'] | bool | None"  [arg-type]
dash_test.py:35: error: "__init__" of "Graph" gets multiple values for keyword argument "config"  [misc]
Found 5 errors in 1 file (checked 1 source file)
(venv) PS C:\Users\gxvh\Python\dash_mypy>
@T4rk1n
Copy link
Contributor

T4rk1n commented Apr 29, 2025

dash_test.py:11: error: Module has no attribute "DataTable" [attr-defined]

mypy cannot find the DataTable from __all__ for some reason, works fine in pyright.

dict(modeBarButtonsToRemove=["sendDataToCloud"])

The config is now a TypedDict which requires the {} syntax eg: {"modeBarButtonsToRemove" :["sendDataToCloud"]}. Plain dict(key="") appears to not be supported by typing systems.

dash_test.py:35: error: "init" of "Graph" gets multiple values for keyword argument "config" [misc]

This is a valid error, config should be before **kwargs and popped from kwargs.

**{"aria-pressed": "false"}

This syntax is not supported by untyped kwargs but should be valid, the only way I found to make it work is to add all the aria props like this:

Aria = TypedDict("Aria", {"aria-pressed": NotRequired[str]})


class Div(Component):
    def __init__(..., **kwargs: Unpack[Aria]):
        ...

But this would requires generating all the possible aria attributes and we also support data-* which can be anything. There is also the cases of components with more than ~256 arguments having **kwargs for the rest of the props so it's not really an option. I'd recommend adding # type: ignore for that case for now.

@gvwilson gvwilson added bug something broken P2 considered for next cycle labels Apr 30, 2025
@gvwilson
Copy link
Contributor

thanks for the report @ghaarsma - we have to focus on other things for a while but will come back to this when we can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P2 considered for next cycle
Projects
None yet
Development

No branches or pull requests

3 participants