Skip to content

Fix variadic ParamSpec expansion crash - #21846

Open
KirschBluteX wants to merge 1 commit into
python:masterfrom
KirschBluteX:fix-21778-variadic-paramspec-crash
Open

Fix variadic ParamSpec expansion crash#21846
KirschBluteX wants to merge 1 commit into
python:masterfrom
KirschBluteX:fix-21778-variadic-paramspec-crash

Conversation

@KirschBluteX

@KirschBluteX KirschBluteX commented Aug 13, 2026

Copy link
Copy Markdown

Fixes #21778.

ExpandTypeVisitor.visit_parameters previously expanded parameter types independently from their kinds and names. A starred Unpack[TypeVarTuple] could therefore reach TypeVarTuple expansion with a concrete tuple replacement and raise NotImplementedError.

This change expands a direct starred TypeVarTuple unpack while updating argument types, kinds, and names in lockstep. Concrete tuple items become positional parameters, while a residual variadic unpack remains starred.

The regression test covers the reported ParamSpec-based context-manager decorator and verifies both the with-target type and the decorated call type.

Tests:

  • python -m pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-parameter-specification.test
  • python -m pytest -n0 mypy/test/testcheck.py::TypeCheckSuite::check-typevar-tuple.test -k "ParamSpec or Unpack"
  • python -m pytest -n0 mypy/test/testtypes.py -k expand
  • python -m mypy --config-file mypy_self_check.ini mypy/expandtype.py
  • python -m ruff check mypy/expandtype.py
  • Targeted pre-commit hooks: trailing-whitespace, end-of-file-fixer, black, ruff-check, codespell

Expand unpacked TypeVarTuple parameters while preserving aligned argument types, kinds, and names.

Fixes python#21778.
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@TheMuffinMan1320

Copy link
Copy Markdown

Looks good!

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