Skip to content

Prevent quadratic runtime for overlap check at large overload counts - #15865

Merged
hauntsaninja merged 6 commits into
python:masterfrom
hauntsaninja:overload-limit
Nov 7, 2026
Merged

hauntsaninja merged 6 commits into
python:masterfrom
hauntsaninja:overload-limit

Conversation

@hauntsaninja

Copy link
Copy Markdown
Collaborator

Fixes #10004

An alternate fix would be to only check the first 100 overloads for overlaps.

@github-actions

This comment has been minimized.

@AlexWaygood AlexWaygood left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternate fix would be to only check the first 100 overloads for overlaps.

I think I'd weakly prefer that? Performance is obviously still very important for us, but it's not as important as it is for pyright, since pyright doubles as a language server. And it feels weird that you might get 50 overlapping-overload errors if you had 99 overloads, but then that number drops to 0 when you added one more overload.

@ilevkivskyi

Copy link
Copy Markdown
Member

Yeah, I don't like silently skipping all checks if there are many overloads. I think we should just limit inner loop to say 100 next items, this way we will check all "nearby" overloads with linear complexity. Also if we hit this limit, we should show an error on the first line saying that some checks were skipped (as we do e.g. for union math). User may then place a single # type: ignore to suppress this warning.

Also we can still always do the implementation completeness check that is linear (and it doesn't affect stubs anyway).

@hauntsaninja
hauntsaninja marked this pull request as draft September 1, 2023 20:11
@hauntsaninja
hauntsaninja marked this pull request as ready for review December 15, 2025 00:44
@hauntsaninja hauntsaninja changed the title Skip overlapping overload check at large overload counts Prevent quadratic runtime for overlap check at large overload counts Dec 15, 2025
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

discord.py (https://github.com/Rapptz/discord.py)
+ discord/client.py:1237: error: Not all overload combinations were checked for overlap because there were too many  [performance-limit]

scipy-stubs (https://github.com/scipy/scipy-stubs)
+ scipy-stubs/sparse/_construct.pyi:142: error: Not all overload combinations were checked for overlap because there were too many  [performance-limit]
+ scipy-stubs/sparse/_construct.pyi:1506: error: Not all overload combinations were checked for overlap because there were too many  [performance-limit]
+ scipy-stubs/sparse/_construct.pyi:1628: error: Not all overload combinations were checked for overlap because there were too many  [performance-limit]
+ scipy-stubs/sparse/_construct.pyi:1750: error: Not all overload combinations were checked for overlap because there were too many  [performance-limit]
+ scipy-stubs/sparse/_construct.pyi:1918: error: Not all overload combinations were checked for overlap because there were too many  [performance-limit]
+ scipy-stubs/sparse/csgraph/_laplacian.pyi:57: error: Not all overload combinations were checked for overlap because there were too many  [performance-limit]

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine to merge as is, but what do you think about doing something like I proposed in this comment #20439 (comment)?

@hauntsaninja

hauntsaninja commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

Okay, I implemented that, but it's a little messy so opening it as a separate PR: #22393

@hauntsaninja
hauntsaninja merged commit 5dc2840 into python:master Nov 7, 2026
26 checks passed
@hauntsaninja
hauntsaninja deleted the overload-limit branch November 7, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Polynomial time-complexity of typing.overload

3 participants