Skip to content

Fully type _operator module#15612

Closed
jonathandung wants to merge 24 commits into
python:mainfrom
jonathandung:patch-6
Closed

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

Conversation

@jonathandung

@jonathandung jonathandung commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Closes: #15611, #15617.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread stdlib/_operator.pyi Outdated
Comment thread stdlib/_operator.pyi Outdated
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread stdlib/_operator.pyi
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@jonathandung

Copy link
Copy Markdown
Contributor Author

No idea why the stubtest failures are emerging...

@AlexWaygood

Copy link
Copy Markdown
Member

No idea why the stubtest failures are emerging...

It's unrelated to your PR. New Python patch releases came out overnight, and it looks like our CI runners have just started using them. I can add a temporary pin to our CI workflow to get things green again, one sec

@AlexWaygood

Copy link
Copy Markdown
Member

#15631

@github-actions

This comment has been minimized.

Comment thread stdlib/_operator.pyi
@jonathandung

Copy link
Copy Markdown
Contributor Author

Since flake8-pyi#539 is progressing much faster than I expected, maybe hold off merging this until that is resolved, then I can remove the # noqa: Y034's.

@jonathandung

Copy link
Copy Markdown
Contributor Author

Sorry, I accidentally made a commit to the wrong branch.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@jonathandung

Copy link
Copy Markdown
Contributor Author

Some weird new errors are emerging, and I can't understand them. Is it a problem with mypy? Because I didn't change anything.

@hauntsaninja

Copy link
Copy Markdown
Collaborator

The _binary_ops_dict thing seems nondeterministic and I think it's caused by previous recent changes to operator. See python/mypy#21445

@github-actions

This comment has been minimized.

Comment thread stdlib/_operator.pyi
@github-actions

This comment has been minimized.

@jonathandung jonathandung requested a review from srittau May 11, 2026 23:51
Comment thread stdlib/_operator.pyi
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

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

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:184: error: Argument 1 to "reduce" has incompatible type overloaded function; expected "Callable[[list[Never], list[str]], list[Never]]"  [arg-type]

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:1368: error: Incompatible types in assignment (expression has type overloaded function, variable has type overloaded function)  [assignment]
+ pandas/core/indexes/datetimes.py:1468: error: Incompatible types in assignment (expression has type overloaded function, variable has type overloaded function)  [assignment]

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]

@jonathandung

Copy link
Copy Markdown
Contributor Author

Will this be merged soon? I have no idea how I would target any of the new mypy_primer errors.

@jonathandung jonathandung deleted the patch-6 branch July 15, 2026 11:13
@jonathandung

Copy link
Copy Markdown
Contributor Author

Sorry, I accidentally deleted this branch again. Will open another PR.

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

6 participants