-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Improve stubs for operator
#13800
Improve stubs for operator
#13800
Conversation
Diff from mypy_primer, showing the effect of this PR on open source code: spark (https://github.com/apache/spark)
+ python/pyspark/core/rdd.py:2159: error: Argument 2 to "fold" of "RDD" has incompatible type "Callable[[SupportsAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[float | Literal[0], float | Literal[0]], float | Literal[0]]" [arg-type]
+ python/pyspark/core/rdd.py:2159: error: Argument 2 to "fold" of "RDD" has incompatible type "Callable[[SupportsAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[complex | Literal[0], complex | Literal[0]], complex | Literal[0]]" [arg-type]
+ python/pyspark/core/rdd.py:2159: error: Argument 2 to "fold" of "RDD" has incompatible type "Callable[[SupportsAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[signedinteger[_32Bit] | Literal[0], signedinteger[_32Bit] | Literal[0]], signedinteger[_32Bit] | Literal[0]]" [arg-type]
+ python/pyspark/core/rdd.py:2159: error: Argument 2 to "fold" of "RDD" has incompatible type "Callable[[SupportsAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[signedinteger[_64Bit] | Literal[0], signedinteger[_64Bit] | Literal[0]], signedinteger[_64Bit] | Literal[0]]" [arg-type]
+ python/pyspark/core/rdd.py:2159: error: Argument 2 to "fold" of "RDD" has incompatible type "Callable[[SupportsAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[floating[_32Bit] | Literal[0], floating[_32Bit] | Literal[0]], floating[_32Bit] | Literal[0]]" [arg-type]
+ python/pyspark/core/rdd.py:2159: error: Argument 2 to "fold" of "RDD" has incompatible type "Callable[[SupportsAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[float64 | Literal[0], float64 | Literal[0]], float64 | Literal[0]]" [arg-type]
+ python/pyspark/core/rdd.py:2159: error: Argument 2 to "fold" of "RDD" has incompatible type "Callable[[SupportsAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[ndarray[Any, Any] | Literal[0], ndarray[Any, Any] | Literal[0]], ndarray[Any, Any] | Literal[0]]" [arg-type]
jax (https://github.com/google/jax)
+ jax/_src/export/shape_poly.py:770: error: Argument 1 to "reduce" has incompatible type "Callable[[SupportsMul[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[int, _DimExpr], int]" [arg-type]
sympy (https://github.com/sympy/sympy)
+ sympy/polys/matrices/dense.py:104: error: Argument 1 to "map" has incompatible type "Callable[[SupportsMul[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[R, Any], R]" [arg-type]
+ sympy/tensor/array/expressions/arrayexpr_derivatives.py:44: error: Argument 1 to "reduce" has incompatible type "Callable[[SupportsAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[tuple[()], Any], tuple[()]]" [arg-type]
+ sympy/tensor/array/expressions/arrayexpr_derivatives.py:45: error: Argument 1 to "reduce" has incompatible type "Callable[[SupportsAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[tuple[()], Any], tuple[()]]" [arg-type]
|
This won't work if you |
This also doesn't cover the reflected cases, i.e. when And if that wasn't complicated enough: When |
Unfortunately, the type system currently can't express the various special rules that apply to |
operator.add
,operator.mul
with existing ProtocolSupportsAdd
,SupportsMul