Skip to content

Commit 88cf8e0

Browse files
authored
fix: optimize overloaded signatures check (#20378)
I've observed numerous calls to `expand_callable_variants` during the investigation of the related issue. However, expanding all the variants for parametrized classes can be time-consuming. Therefore, we should only expand callable variants once. This optimization reduces the processing time from approximately 400 seconds to 7 seconds when using non-compiled mypy in the provided case. Refs: nipunn1313/mypy-protobuf#707
1 parent ab63d64 commit 88cf8e0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mypy/checker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8751,8 +8751,9 @@ def is_unsafe_overlapping_overload_signatures(
87518751
# Note: We repeat this check twice in both directions compensate for slight
87528752
# asymmetries in 'is_callable_compatible'.
87538753

8754+
other_expanded = expand_callable_variants(other)
87548755
for sig_variant in expand_callable_variants(signature):
8755-
for other_variant in expand_callable_variants(other):
8756+
for other_variant in other_expanded:
87568757
# Using only expanded callables may cause false negatives, we can add
87578758
# more variants (e.g. using inference between callables) in the future.
87588759
if is_subset_no_promote(sig_variant.ret_type, other_variant.ret_type):

0 commit comments

Comments
 (0)