Skip to content

Commit f47a455

Browse files
committed
restrict
1 parent ba15d7d commit f47a455

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

mypy/checker.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,10 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
892892
# useful for stubs!
893893
return
894894

895-
if len(defn.items) >= 100:
896-
# Skip this check for large numbers of overloads, since the following is quadratic.
897-
# This constant matches the threshold at which pyright similarly skips this check.
898-
return
895+
max_overload_count = 50
896+
if len(defn.items) >= max_overload_count:
897+
# Since the following is quadratic, we limit the size of the inner loop
898+
self.fail(message_registry.TOO_MANY_OVERLOADS, defn)
899899

900900
# Compute some info about the implementation (if it exists) for use below
901901
impl_type: CallableType | None = None
@@ -919,6 +919,10 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
919919
continue
920920

921921
for j, item2 in enumerate(defn.items[i + 1 :]):
922+
if j >= max_overload_count:
923+
# Avoid quadratic blowup for large numbers of overloads.
924+
break
925+
922926
assert isinstance(item2, Decorator)
923927
sig2 = self.extract_callable_type(item2.var.type, item2)
924928
if sig2 is None:

mypy/message_registry.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
106106
"Overloaded method has both abstract and non-abstract variants"
107107
)
108108
MULTIPLE_OVERLOADS_REQUIRED: Final = ErrorMessage("Single overload definition, multiple required")
109+
TOO_MANY_OVERLOADS: Final = ErrorMessage(
110+
"Not all overload combinations were checked for overlap because there were too many"
111+
)
109112
READ_ONLY_PROPERTY_OVERRIDES_READ_WRITE: Final = ErrorMessage(
110113
"Read-only property cannot override read-write property"
111114
)

0 commit comments

Comments
 (0)