Skip to content

Fully type _operator module - #16014

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

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

Conversation

@jonathandung

@jonathandung jonathandung commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Closes #15611.

@github-actions

This comment has been minimized.

@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

@jonathandung

Copy link
Copy Markdown
Contributor Author

write a comment showing that the change is positive?

Sorry, but I'm not sure what you mean. Besides, some of my changes are interdependent. I think I can still split them up, it would just be a Herculean task.

@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]

pandas (https://github.com/pandas-dev/pandas)
- pandas/core/roperator.py:56: error: Call to untyped function "and_" in typed context  [no-untyped-call]
- pandas/core/roperator.py:60: error: Call to untyped function "or_" in typed context  [no-untyped-call]
- pandas/core/roperator.py:64: error: Call to untyped function "xor" in typed context  [no-untyped-call]
+ 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:1563: error: Incompatible types in assignment (expression has type overloaded function, variable has type overloaded function)  [assignment]
+ pandas/core/indexes/datetimes.py:1513: error: Incompatible types in assignment (expression has type overloaded function, variable has type overloaded function)  [assignment]

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:628: error: Argument 1 to "reduce" has incompatible type overloaded function; expected "Callable[[Replace, Replace], Replace]"  [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

mypy-primer shows that this change will introduce new type errors into a number of projects. Is that a good thing?

@jonathandung

jonathandung commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

Certainly not, but as I said in the previous iteration of this PR, I am unable to understand most of those errors and have little idea how to fix them. It would be much appreciated if I could get some guidance on this.

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