Skip to content

Tighten detection of non-local partial None types - #22437

Merged
ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:narrow-init-none
Nov 12, 2026
Merged

ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:narrow-init-none

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Member

We support non-local partial None types by detecting functions that may infer variables, and processing them as part of top-levels. However, currently this is triggered on assignment to any inferred variable. This PR limits this only to inferred variables with an initial assignment to literal None only. This should make parallel type-checking a bit faster (especially after we will start splitting large SCCs)

cc @JukkaL

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

bokeh (https://github.com/bokeh/bokeh)
+ src/bokeh/util/compiler.py: note: In function "set_cache_hook":
+ src/bokeh/util/compiler.py:282:31: error: Incompatible types in assignment (expression has type "Callable[[CustomModel, Implementation], AttrDict | None]", variable has type "def _model_cache_no_op(model: CustomModel, implementation: Implementation) -> AttrDict | None")  [assignment]

@ilevkivskyi

Copy link
Copy Markdown
Member Author

New error in bokeh is expected. IIUC it is caused by argument names (or rather absence of them in Callable). Previously we processed assignments in different order, so that we assigned a wider type first.

@ilevkivskyi
ilevkivskyi merged commit 332915e into python:master Nov 12, 2026
25 checks passed
@ilevkivskyi
ilevkivskyi deleted the narrow-init-none branch November 12, 2026 00:50
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