From d43786cd4fd456ddce5b6bc34055220c6113f931 Mon Sep 17 00:00:00 2001 From: subnix Date: Mon, 8 Dec 2025 17:48:59 +0400 Subject: [PATCH] fix: optimize overloaded signatures check It may take a while to expand all the variants for parametrized classes. So we should expand other's callable variants only once. Refs: https://github.com/nipunn1313/mypy-protobuf/issues/707 --- mypy/checker.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/checker.py b/mypy/checker.py index 841b3a905c65..7c54d99e0afe 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -8751,8 +8751,9 @@ def is_unsafe_overlapping_overload_signatures( # Note: We repeat this check twice in both directions compensate for slight # asymmetries in 'is_callable_compatible'. + other_expanded = expand_callable_variants(other) for sig_variant in expand_callable_variants(signature): - for other_variant in expand_callable_variants(other): + for other_variant in other_expanded: # Using only expanded callables may cause false negatives, we can add # more variants (e.g. using inference between callables) in the future. if is_subset_no_promote(sig_variant.ret_type, other_variant.ret_type):