The original bug report is optuna/optuna#4404.
I tried to make a minimal reproducible example and found that checking the following code with the latest mypy takes about 1 minute.
This takes 6 s with compiled mypy 1.15.0. Adding one more term increases runtime to 18 s. The dependency (time vs number of terms) is $T \approx 3^N$ after 7-8 terms. For every relevant overload signature (3 out of 5 here), we accept all arguments. When we have 10 such overloads nested, we accept the "leaf" nodes 0 and 1 $3^{10} \approx 60,000$ times.
np.ndarray.__mul__ is an overload with 17 variants, 9 of which match NDArray[np.floating] argument, so it grows even faster.
Activity
sterliakov commented on Apr 22, 2025
Minimal repro without generics and third-party deps:
This takes 6 s with compiled mypy 1.15.0. Adding one more term increases runtime to 18 s. The dependency (time vs number of terms) is $T \approx 3^N$ after 7-8 terms. For every relevant overload signature (3 out of 5 here), we accept all arguments. When we have 10 such overloads nested, we accept the "leaf" nodes 0 and 1 $3^{10} \approx 60,000$ times.
np.ndarray.__mul__ is an overload with 17 variants, 9 of which match NDArray[np.floating] argument, so it grows even faster.
Use cache for OpExpr (python#19523)