Skip to content

Bump mypy to 2.4.0 and annotate PAGE_REGISTRY - #4145

Open
invisiblefix-bot wants to merge 2 commits into
plotly:devfrom
invisiblefix-bot:invisiblefix/fix-pr-4141
Open

invisiblefix-bot wants to merge 2 commits into
plotly:devfrom
invisiblefix-bot:invisiblefix/fix-pr-4141

Conversation

@invisiblefix-bot

Copy link
Copy Markdown

Supersedes #4141 (Dependabot: bump mypy from 1.15.0 to 2.4.0 in the pip-dependencies group). This PR includes that update unchanged (requirements/ci.txt: mypy==2.4.0), plus a 1-line fix so the Typing Tests job passes again.

Root cause. mypy 2.0 turned on --local-partial-types by default (mypy 2.0 changelog, "Enable --local-partial-types by Default", python/mypy#21163), so mypy no longer infers the type of an empty module-level container from assignments made later inside a function. PAGE_REGISTRY = collections.OrderedDict() in dash/_pages.py depended on that (it is only filled inside register_page()), so every mypy run that imports dash reports dash/_pages.py:20: error: Need type annotation for "PAGE_REGISTRY" [var-annotated]. 11 mypy cases in tests/compliance fail on it.

Fix. PAGE_REGISTRY: collections.OrderedDict = collections.OrderedDict(). This is the same style dash.py already uses for _mcp_callback_maps.

  • Runtime: the object is unchanged, an empty collections.OrderedDict. The only difference is that dash._pages.__annotations__ now has a PAGE_REGISTRY entry.
  • Typing: reveal_type(dash._pages.PAGE_REGISTRY) is collections.OrderedDict[Any, Any] with mypy 1.15.0 before the change, and also with both mypy 1.15.0 and 2.4.0 after it, so type checking of code that uses dash.page_registry stays the same.
  • No test, test config or CI config was changed. I didn't add a CHANGELOG entry because this is a dev-dependency and typing-only change with no user-facing effect. Happy to add one if you'd like.

Evidence (Typing Tests job command: pytest tests/compliance/test_typing.py tests/compliance/test_callback_typing.py; Ubuntu 22.04, Python 3.12.16, Node 24.21.0, installed the way CI does it: built wheel [ci,testing,dev,diskcache] plus npm run setup-tests.py)

Run Commit mypy Collected Passed Failed Skipped
base 1 ce7fc72 (dev, #4141's base) 1.15.0 55 54 0 1
base 2 ce7fc72 1.15.0 55 54 0 1
head 1 de138b9 (#4141) 2.4.0 55 43 11 1
head 2 de138b9 2.4.0 55 43 11 1
fix 1 56ff304 (this PR) 2.4.0 55 54 0 1
fix 2 56ff304 2.4.0 55 54 0 1

All six runs collected the same 55 test IDs. Both head runs failed the same 11 IDs, and these match #4141's CI run (job). The one skip (test_typi001_component_typing[element=set()-assertions22]) is skipped on every run. pytest tests/unit gives 741 collected, 734 passed, 0 failed, 7 skipped on both head and fix. black, flake8 and pylint (via the repo's lint-staged hook) pass on the changed file. The Selenium integration jobs were not run locally.

Fix commit: 56ff304ce2f564aafd8494386cbba36df1ed2890

dependabot Bot and others added 2 commits November 10, 2026 14:23
Bumps the pip-dependencies group with 1 update: [mypy](https://github.com/python/mypy).


Updates `mypy` from 1.15.0 to 2.4.0
- [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md)
- [Commits](python/mypy@v1.15.0...v2.4.0)

---
updated-dependencies:
- dependency-name: mypy
  dependency-version: 2.4.0
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: pip-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
mypy 2.0 turned on --local-partial-types by default, so the empty collections.OrderedDict() assigned to the module-level PAGE_REGISTRY can no longer get its type from assignments inside register_page(), and mypy reports 'Need type annotation for "PAGE_REGISTRY" [var-annotated]' whenever it checks code that imports dash.

Annotate it as collections.OrderedDict, which is the type mypy 1.15 inferred (OrderedDict[Any, Any]) and the same style dash.py uses for _mcp_callback_maps. The runtime object is unchanged.
@sonarqubecloud

Copy link
Copy Markdown

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.

1 participant