Repository navigation
Fix crash in function with unpack and constrained TypeVar - #22107
Conversation
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
| ) | ||
| if needs_normalization: | ||
| if needs_normalization and self.normalize_callables: | ||
| return expanded.with_normalized_var_args() |
There was a problem hiding this comment.
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
Fixes #21907
This fixes the crash by not normalizing callables too soon (note the
TypedDicttest passes on master, but I still add it to prevent similar regression there).cc @JukkaL