Skip to content

Fix crash in function with unpack and constrained TypeVar - #22107

Merged
ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:fix-exp-norm-crash
Oct 5, 2026
Merged

ilevkivskyi merged 1 commit into
python:masterfrom
ilevkivskyi:fix-exp-norm-crash

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Member

Fixes #21907

This fixes the crash by not normalizing callables too soon (note the TypedDict test passes on master, but I still add it to prevent similar regression there).

cc @JukkaL

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

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

@ilevkivskyi
ilevkivskyi merged commit 0967b8a into python:master Oct 5, 2026
25 checks passed
@ilevkivskyi
ilevkivskyi deleted the fix-exp-norm-crash branch October 5, 2026 12:16
Comment thread mypy/expandtype.py
)
if needs_normalization:
if needs_normalization and self.normalize_callables:
return expanded.with_normalized_var_args()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can confirm this change resolves the issue reported in #21907 .

In my proposed fix for #21907
in willy-b@eb59611 from 2026-09-17 (2026-09-16 PT),

I also found it sufficient to avoid calling expanded.with_normalized_var_args() here
downstream of checker.py expand_typevars, also adding a optional parameter to expand_type as you do here setting a flag on ExpandTypeVisitor controlling whether to normalize here.

However I was divided between stopping the with_normalized_var_args call directly here as you do or stopping needs_normalization from being set above at:

if var_arg is not None and isinstance(var_arg.typ, UnpackType):
            needs_normalization = True
            arg_types = self.interpolate_args_for_unpack(t, var_arg.typ)
        else:
            arg_types = self.expand_types(t.arg_types)

I had not confirmed where interpolate_args_for_unpack was being used to determine whether that should still be run or not in this case (expanded.with_normalized_var_args() is sufficient to fix this one issue but I was worried about side effects of that or this approach). Thanks

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.

"INTERNAL_ERROR": generic fun w/ Callable param w/ constrained return type followed by *args typed as *Tuple[int, float] crashes mypy

3 participants