Skip to content

Conversation

@hauntsaninja
Copy link
Collaborator

Fixes #10004

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

@github-actions

This comment has been minimized.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

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
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
Copy link
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:1233: error: Not all overload combinations were checked for overlap because there were too many  [misc]

scipy-stubs (https://github.com/scipy/scipy-stubs)
+ scipy-stubs/sparse/_construct.pyi:118: error: Not all overload combinations were checked for overlap because there were too many  [misc]
+ scipy-stubs/sparse/_construct.pyi:1362: error: Not all overload combinations were checked for overlap because there were too many  [misc]
+ scipy-stubs/sparse/_construct.pyi:1493: error: Not all overload combinations were checked for overlap because there were too many  [misc]
+ scipy-stubs/sparse/_construct.pyi:1623: error: Not all overload combinations were checked for overlap because there were too many  [misc]
+ scipy-stubs/sparse/_construct.pyi:1771: error: Not all overload combinations were checked for overlap because there were too many  [misc]

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