Repository navigation
Bump mypy to 2.4.0 and annotate PAGE_REGISTRY - #4145
Open
invisiblefix-bot wants to merge 2 commits into
Open
invisiblefix-bot wants to merge 2 commits into
invisiblefix-bot wants to merge 2 commits into
Conversation
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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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-typesby default (mypy 2.0 changelog, "Enable--local-partial-typesby 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()indash/_pages.pydepended on that (it is only filled insideregister_page()), so every mypy run that imports dash reportsdash/_pages.py:20: error: Need type annotation for "PAGE_REGISTRY" [var-annotated]. 11 mypy cases intests/compliancefail on it.Fix.
PAGE_REGISTRY: collections.OrderedDict = collections.OrderedDict(). This is the same styledash.pyalready uses for_mcp_callback_maps.collections.OrderedDict. The only difference is thatdash._pages.__annotations__now has aPAGE_REGISTRYentry.reveal_type(dash._pages.PAGE_REGISTRY)iscollections.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 usesdash.page_registrystays the same.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]plusnpm run setup-tests.py)dev, #4141's base)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/unitgives 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