Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Relax overload checks to allow return types to be regular subtypes #5064
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.