Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Closes #15617 as well. |
This comment has been minimized.
This comment has been minimized.
JelleZijlstra
left a comment
There was a problem hiding this comment.
You can add test cases in stdlib/@tests/test_cases, though we generally do so only in exceptionally complicated cases and I'm not sure any of the changes here need them.
It would also be helpful to look over the mypy-primer results and see if the changes are desirable.
stdlib/_operator.pyi
Outdated
| def ixor(a, b, /): ... | ||
| def iadd(a: _SupportsIAdd[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... | ||
| def iand(a: _SupportsIAnd[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... | ||
| def iconcat(a: MutableSequence[_T], b: Sequence[_T], /) -> MutableSequence[_T]: ... |
There was a problem hiding this comment.
This is imprecise and I think it's causing the schemathesis error. This annotation doesn't express that it returns the same kind of MutableSequence as its argument. I'm not sure that is expressible while also typing b precisely.
There was a problem hiding this comment.
I tried to find a way to overcome this issue as well but failed. To my knowledge, the current type system does not allow capturing both the exact type of a protocol and its type parameters simultaneously (upper bound of TypeVar cannot be generic).
|
Diff from mypy_primer, showing the effect of this PR on open source code: sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/ext/autodoc/_legacy_class_based/_documenters.py: note: In member "should_suppress_value_header" of class "DataDocumenter":
+ sphinx/ext/autodoc/_legacy_class_based/_documenters.py:2078:44: error: Argument 1 to "reduce" has incompatible type "Callable[[_SupportsIAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[list[Never], list[str]], list[Never]]" [arg-type]
+ sphinx/ext/autodoc/_legacy_class_based/_documenters.py:2078:44: error: Argument 1 to "reduce" has incompatible type "Callable[[_SupportsIAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[Iterable[str], list[str]], Iterable[str]]" [arg-type]
+ sphinx/ext/autodoc/_legacy_class_based/_documenters.py: note: In member "should_suppress_value_header" of class "AttributeDocumenter":
+ sphinx/ext/autodoc/_legacy_class_based/_documenters.py:2730:48: error: Argument 1 to "reduce" has incompatible type "Callable[[_SupportsIAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[list[Never], list[str]], list[Never]]" [arg-type]
+ sphinx/ext/autodoc/_legacy_class_based/_documenters.py:2730:48: error: Argument 1 to "reduce" has incompatible type "Callable[[_SupportsIAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[Iterable[str], list[str]], Iterable[str]]" [arg-type]
xarray (https://github.com/pydata/xarray)
+ xarray/core/accessor_str.py: note: In member "get_dummies" of class "StringAccessor":
+ xarray/core/accessor_str.py:2836: error: Argument 1 to "reduce" has incompatible type overloaded function; expected "Callable[[Iterable[Any], Iterable[Any]], Iterable[Any]]" [arg-type]
colour (https://github.com/colour-science/colour)
+ colour/io/luts/lut.py:642: error: Cannot call function of unknown type [operator]
+ colour/continuous/signal.py:1093: error: Cannot call function of unknown type [operator]
+ colour/continuous/signal.py:1097: error: Cannot call function of unknown type [operator]
Tanjun (https://github.com/FasterSpeeding/Tanjun)
+ tanjun/conversion.py:133: error: Argument 1 to "reduce" has incompatible type "Callable[[_SupportsIOr[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[CacheComponents, CacheComponents], CacheComponents]" [arg-type]
+ tanjun/conversion.py:156: error: Argument 1 to "reduce" has incompatible type "Callable[[_SupportsIOr[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[Intents, Intents], Intents]" [arg-type]
schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/cli/validation.py: note: In function "reduce_list":
+ src/schemathesis/cli/validation.py:184: error: Argument 1 to "reduce" has incompatible type "Callable[[_SupportsIAdd[_T_contra, _T_co], _T_contra], _T_co]"; expected "Callable[[list[Never], list[str]], list[Never]]" [arg-type]
kornia (https://github.com/kornia/kornia)
+ kornia/feature/sold2/backbones.py:79: error: Argument 1 to "reduce" has incompatible type "Callable[[MutableSequence[_T], Sequence[_T]], MutableSequence[_T]]"; expected "Callable[[list[int], list[int]], list[int]]" [arg-type]
jax (https://github.com/google/jax)
- jax/_src/pallas/pipelining/schedulers.py:241: error: Argument 1 to "reduce" has incompatible type "BinaryUfunc | Callable[[Any, Any], Any]"; expected "Callable[[bool, Array | bool], bool]" [arg-type]
+ jax/_src/pallas/pipelining/schedulers.py:241: error: Argument 1 to "reduce" has incompatible type "BinaryUfunc | overloaded function"; expected "Callable[[bool, Array | bool], bool]" [arg-type]
- jax/_src/pallas/pipelining/schedulers.py:270: error: Incompatible types in assignment (expression has type "Array | Any", variable has type "bool") [assignment]
+ jax/_src/pallas/pipelining/schedulers.py:270: error: Incompatible types in assignment (expression has type "object", variable has type "bool") [assignment]
- jax/_src/pallas/pipelining/schedulers.py:277: error: Incompatible types in assignment (expression has type "Array | Any", variable has type "bool") [assignment]
+ jax/_src/pallas/pipelining/schedulers.py:277: error: Incompatible types in assignment (expression has type "object", variable has type "bool") [assignment]
- jax/_src/pallas/pipelining/schedulers.py:303: error: Argument 1 to "reduce" has incompatible type "BinaryUfunc | Callable[[Any, Any], Any]"; expected "Callable[[list[Array | bool], Array | bool], list[Array | bool]]" [arg-type]
+ jax/_src/pallas/pipelining/schedulers.py:303: error: Argument 1 to "reduce" has incompatible type "BinaryUfunc | overloaded function"; expected "Callable[[list[Array | bool], Array | bool], list[Array | bool]]" [arg-type]
ibis (https://github.com/ibis-project/ibis)
+ ibis/util.py:268: error: Incompatible types in assignment (expression has type "overloaded function | overloaded function", variable has type overloaded function) [assignment]
+ ibis/expr/api.py:746: error: Argument 1 to "reduce" has incompatible type overloaded function; expected "Callable[[BooleanValue | bool, BooleanValue | bool], BooleanValue | bool]" [arg-type]
+ ibis/expr/api.py:766: error: Argument 1 to "reduce" has incompatible type overloaded function; expected "Callable[[BooleanValue | bool, BooleanValue | bool], BooleanValue | bool]" [arg-type]
+ ibis/backends/sql/compilers/base.py:633: error: Argument 1 to "reduce" has incompatible type overloaded function; expected "Callable[[Replace, Replace], Replace]" [arg-type]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/computation/ops.py:328: error: Need type annotation for "_binary_ops_dict" (hint: "_binary_ops_dict: dict[<type>, <type>] = ...") [var-annotated]
+ pandas/core/algorithms.py:1346: error: Incompatible types in assignment (expression has type overloaded function, variable has type overloaded function) [assignment]
+ pandas/core/indexes/datetimes.py:1385: error: Incompatible types in assignment (expression has type overloaded function, variable has type overloaded function) [assignment]
|
Closes: #15611, #15617.
This is a big change, my annotations may have some formatting issues, and I don't know how to add tests; however, I will not make this a draft to potentially get more suggestions.