Relax overload checks to allow return types to be regular subtypes #5064
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.
This pull request relaxes the overlapping overload checks so that if the parameter types of an alternative are a proper subtype of another, the return type needs to only be a regular subtype, not a proper subtype.
The net effect is that the return type of the first alternative is allowed to be 'Any'.
This does make overloads slightly less safe, but 'Any' was always meant to be an escape hatch, so I'm figuring this is fine.
Rationale: My proposed changes on overhauling overloads require a few changes to typeshed -- relevant pull request here. Rather then trying to change both at the same time, I want to get typeshed working first.
This was pretty easy to do, apart from the attrs stubs. The issue basically boils down to this:
This code typechecks under the current system because alternative 1 completely shadows alternative 2. It fails to typecheck under the new system for the exact same reason.
If we swap the two alternatives, it fails under the current system because 'Any' is not a proper subtype of 'T'.
It is, however, regular subtype of 'T' -- hence this change.