-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking issue for overloads #5119
Comments
Just for myself, a simple summary of current logic:
@Michael0x2a did I miss something? |
@ilevkivskyi -- No, I think that looks good. A few tweaks:
|
Yes, I remember we discussed this, we can do this is mypy, but this doesn't need to be in spec/PEP 484 just to make the mental model more "compact". |
@Michael0x2a what is your timeline for working on this? 0.620 release will be around June 29 (right after Python 3.7) and I will be the release manager. I will be glad to see better support for overloads in (since this is a big and long awaited feature). Do you think we can make it? If needed, I can review the PRs faster/devote more time to this. |
@ilevkivskyi: In short, I think I can have the overload TODOs and the bulk of the issues ready by then; I'm a bit less certain about operator methods. Specifically:
|
OK, this is perfect.
There is also a related issue that dunder code is quite old, most of it is not using
This is great! |
This commit addresses TODO 2 from python#5119 by adding support for detecting overloads with partially overlapping arities. It also refactors the `is_callable_compatible` method. Specifically, this pull request... 1. Pulls out a lot of the logic for iterating over formal arguments into a helper method in CallableType. 2. Pulls out logic for handling varargs and kwargs outside of loops. 3. Rearranges some of the logic so we can return earlier slightly more frequently.
This commit addresses TODO 2 from #5119 by adding support for detecting overloads with partially overlapping arities. It also refactors the `is_callable_compatible` method. Specifically, this pull request... 1. Pulls out a lot of the logic for iterating over formal arguments into a helper method in CallableType. 2. Pulls out logic for handling varargs and kwargs outside of loops. 3. Rearranges some of the logic so we can return earlier slightly more frequently.
On a second thought, I think we can just skip this. Although it would flag some weird definitions, this is not technically type unsafe, and unlike the "... will be never matched" error (which is also technically not type unsafe, but is obvious) may only confuse users. |
I just read again through the list and propose to focus on three things before the next release (apart from finishing the existing PRs):
|
@ilevkivskyi -- sounds good to me. I have a PR for partially-overlapping types that I'm working on right now. It still needs a loooot more testing, but hopefully it'll be ready for review during the next few days or so.
Also sounds good -- I agree that we can probably find a few easy wins. |
I will need to take a day of rest, I can review your PRs on Sunday morning. |
While I don't think every single item mentioned in this tracking issue has been finished, the vast majority is done and the remaining work can live as independent issues. The only thing that doesn't have an issue is general refactoring and clean up, would one be useful @Michael0x2a? |
This is an issue summarizing all remaining TODOs for the overloads overhaul.
Done
Add support for detecting partially-overlapping arities.
For example, disallow
f(A, A) -> int
andf(*A) -> str
. This will likely require modifications tois_callable_compatible
(or require implementing a new, similar method).Improve union math semantics. Related issues:
Update docs to clarify what the new overload semantics are. Related issues:
Improving how overload implementations are checked. Related issues:
Add full support for partially-overlapping types.
For example, disallow
f(Union[A, B]) -> int
andf(Union[B, C]) -> str
. We currently support detect partially-overlapping unions and tuples on just the top-level.Related issues:
Sub-todos:
If all arguments in the first overload are partially overlapping with the second, report an error (even if the first return type is narrower).
We should also probably have a custom error message, since this is technically safe when the first return type is narrower. This should also probably wait until we have more robust support for partially-overlapping types.
Edit: We decided it wasn't worth complicating the code to handle this TODO.
In-progress
Add union math for operators. See Mypy fails on
Union[float, int] + Union[float, int]
#2128.Error messages need a usability overhaul. Related open issues:
Remaining todos:
Overload subtypes could be enhanced to use the new union math algorithms in some way. Related open issues:
Improve test coverage:
Sub-TODOs:
Update PEP 484/submit a new mini-PEP or something.
Remaining todos; deprioritized
Re-think how overloads, operator overloading, and overload subtyping interacts. Related open issues:
Sub-TODOs:
Update code for operator methods to take advantages of the overload refactorings.
For example, I think operator methods currently might be ignoring generics when checking for overlaps (though it's unclear if this is actually an issue in real-life code). This mostly boils down to using
is_callable_compatible
in clever ways withinis_unsafe_overlapping_operator_signatures
and adding more tests.Enhance binder to understand how overloads and NoReturn interact. Related issues:
General refactoring and cleanup:
Adjust the semantic analysis phase so we use the same binding for a typevar across all overload alternatives.
This would let us remove
merge_typevars_in_callables_by_name
. Implementing this would probably require refactoringTypeVarScope
?Improving how overloads and decorators interact. Related issues:
Issues that need triaging
The text was updated successfully, but these errors were encountered: