Skip to content

Fully type _operator module - #16014

Open
jonathandung wants to merge 24 commits into
python:mainfrom
jonathandung:patch-5
Open

Fully type _operator module#16014
jonathandung wants to merge 24 commits into
python:mainfrom
jonathandung:patch-5

Conversation

@jonathandung

@jonathandung jonathandung commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Closes: #15611, #15617, #16211.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

kornia (https://github.com/kornia/kornia)
+ kornia/feature/sold2/backbones.py:92: 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]

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]

schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/cli/validation.py: note: In function "reduce_list":
+ src/schemathesis/cli/validation.py:186: error: Argument 1 to "reduce" has incompatible type overloaded function; expected "Callable[[list[Never], list[str]], list[Never]]"  [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]

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]

jax (https://github.com/google/jax)
- jax/_src/pallas/pipelining/schedulers.py:236: 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:236: 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:265: error: Incompatible types in assignment (expression has type "Array | Any", variable has type "bool")  [assignment]
+ jax/_src/pallas/pipelining/schedulers.py:265: error: Incompatible types in assignment (expression has type "object", variable has type "bool")  [assignment]
- jax/_src/pallas/pipelining/schedulers.py:272: error: Incompatible types in assignment (expression has type "Array | Any", variable has type "bool")  [assignment]
+ jax/_src/pallas/pipelining/schedulers.py:272: error: Incompatible types in assignment (expression has type "object", variable has type "bool")  [assignment]
- jax/_src/pallas/pipelining/schedulers.py:298: 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:298: error: Argument 1 to "reduce" has incompatible type "BinaryUfunc | overloaded function"; expected "Callable[[list[Array | bool], Array | bool], list[Array | bool]]"  [arg-type]

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 overloaded function; 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 overloaded function; 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 overloaded function; 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 overloaded function; expected "Callable[[Iterable[str], list[str]], Iterable[str]]"  [arg-type]

@JelleZijlstra

Copy link
Copy Markdown
Member

This is a lot of changes and the mypy-primer output is not clearly positive. These changes may be correct in principle but it's not clear they all help users. Could you make smaller PRs and if mypy-primer shows any changes, write a comment showing that the change is positive?

@OutSquareCapital

OutSquareCapital commented Aug 15, 2026

Copy link
Copy Markdown

I struggle to see why they couldn't help users.

As of today the use of operator module is encouraged by populars linters such as Ruff when it can replace lambdas, but some basic function are not typed, defeating all their purpose on strict type checking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standard library _operator module is poorly typed

5 participants