-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
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:
- Allow overloading based on TypedDict structure
- Overloaded function signatures 1 and 2 overlap with incompatible return types
- Allow overloads to be distinguished by contained type of a generic
- spurious "Need type annotation" error with overloads
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:
- Add test cases for situations where the overload definitions have a type error (that may or may not have been type-ignored).
-
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:
- Make operator overloading overlapping checks more lenient
- Ordering matters for @overload (one of the error messages seems like a bug)
- Overloading function issues (incompatible with supertype).
- Signatures of overloaded operators are incompatible with super type
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: