Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,11 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
# useful for stubs!
return

max_overload_count = 50
if len(defn.items) >= max_overload_count:
# Since the following is quadratic, we limit the size of the inner loop
self.fail(message_registry.TOO_MANY_OVERLOADS, defn)

# Compute some info about the implementation (if it exists) for use below
impl_type: CallableType | None = None
if defn.impl:
Expand All @@ -914,6 +919,10 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
continue

for j, item2 in enumerate(defn.items[i + 1 :]):
if j >= max_overload_count:
# Avoid quadratic blowup for large numbers of overloads.
break

assert isinstance(item2, Decorator)
sig2 = self.extract_callable_type(item2.var.type, item2)
if sig2 is None:
Expand Down
3 changes: 3 additions & 0 deletions mypy/message_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
"Overloaded method has both abstract and non-abstract variants"
)
MULTIPLE_OVERLOADS_REQUIRED: Final = ErrorMessage("Single overload definition, multiple required")
TOO_MANY_OVERLOADS: Final = ErrorMessage(
"Not all overload combinations were checked for overlap because there were too many"
)
READ_ONLY_PROPERTY_OVERRIDES_READ_WRITE: Final = ErrorMessage(
"Read-only property cannot override read-write property"
)
Expand Down