Allow non-Any gradual return types for ambiguous overloads - #2350
Open
carljm wants to merge 1 commit into
Open
Conversation
jorenham
approved these changes
Aug 27, 2026
jorenham
left a comment
Collaborator
There was a problem hiding this comment.
I really like this; thanks!
5 tasks
davidhalter
approved these changes
Aug 28, 2026
davidhalter
left a comment
Collaborator
There was a problem hiding this comment.
Wow, if I knew it was this simple I would have done that a long time ago. I have preferred Mypy's behavior in this case and I'm happy to reintroduce it in Zuban. I originally was unhappy to remove it, because it feels much better (and I hope this improves Zuban for scipy-stubs and similar cases)...
I still feel that AnyOf might be useful, but this is great for now.
Thanks a lot!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The spec's requirement to infer
Anyfor gradually-ambiguous overload evaluations is a regular source of discontent, as a more precise type could often still meet the graduality requirement that the inferred return type can be gradually used as if it were any of the matched-overload return types.In fact mypy already does infer more precise types that meet this requirement. For example, mypy combines ambiguous overload returns of
list[int]andlist[str]intolist[Any], which is gradually usable as eitherlist[int]orlist[str], and is clearly preferable toAnyin its precision.Adjust the spec language and the conformance suite tests to express the actual graduality requirements, instead of requiring exactly
Any.An inference of
Anyremains spec-compliant under this change, but more precise gradual types that still meet the graduality requirement can also be spec-compliant.