Visitar URL original
Fix crash on non-normalized parameters expansion by ilevkivskyi · Pull Request #22123 · python/mypy · GitHub
Skip to content

Fix crash on non-normalized parameters expansion - #22123

Merged
ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:fix-params-norm
Oct 8, 2026
Merged

ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:fix-params-norm

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Member

Fixes #21778

Fix by itself trivial: Parameters require the same level of care as CallableType when expanding. However, we have already a bunch of code duplication between two, and this PR would have added another ~80 lines of duplicated code, so I decided to refactor all shared logic into a separate base class.

I verified that this causes no visible slow-down on self-check (compiled, -n0):

master                    3.989s (0.0%) | stdev 0.012s 
fix-params-norm           3.975s (-0.4%) | stdev 0.011s

cc @JukkaL

@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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

scipy-stubs (https://github.com/scipy/scipy-stubs)
- tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

@JukkaL JukkaL changed the title Fix crash on non-nomralized parameters expansion Fix crash on non-normalized parameters expansion Oct 8, 2026

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring and fix look good (negative lines of code for the PR!), I just have one question.

Comment thread mypy/expandtype.py
return t.copy_modified(arg_types=self.expand_types(t.arg_types))
# This mimics the logic in visit_callable_type().
var_arg = t.var_arg()
needs_normalization = False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also look at self.normalize_callables -- is it relevant here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I think we are fine (even for callables we really need to keep original shape only for top-level callables).

@ilevkivskyi
ilevkivskyi merged commit 6a6979c into python:master Oct 8, 2026
25 checks passed
@ilevkivskyi
ilevkivskyi deleted the fix-params-norm branch October 8, 2026 16:17
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.

Crash with variadic type variable

2 participants