Skip to content

Conversation

jorenham
Copy link
Member

@jorenham jorenham commented Sep 7, 2025

Follow-up of #29695, partially addressing python/mypy#15993 (comment)

This only leaves floating, timedelta64, and datetime64.

@jorenham jorenham marked this pull request as draft September 7, 2025 18:18
@jorenham jorenham changed the title TYP: fix np.*integer method declaration TYP: fix np.number and np.*integer method declaration Sep 7, 2025
Copy link

github-actions bot commented Sep 7, 2025

Diff from mypy_primer, showing the effect of this PR on type check results on a corpus of open source code:

jax (https://github.com/google/jax)
+ jax/_src/basearray.pyi:111: error: Unused "type: ignore" comment  [unused-ignore]
+ jax/_src/basearray.pyi:112: error: Unused "type: ignore" comment  [unused-ignore]
+ jax/_src/basearray.pyi:113: error: Unused "type: ignore" comment  [unused-ignore]
+ jax/_src/basearray.pyi:115: error: Unused "type: ignore" comment  [unused-ignore]
+ jax/_src/basearray.pyi:119: error: Unused "type: ignore" comment  [unused-ignore]

freqtrade (https://github.com/freqtrade/freqtrade)
- freqtrade/data/converter/orderflow.py:175: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "str"; expected "complex | number[Any, int | float | complex] | numpy.bool[builtins.bool]"  [arg-type]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("str" and "integer[Any]")  [operator]
- freqtrade/data/converter/orderflow.py:175: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "bytes"; expected "complex | number[Any, int | float | complex] | numpy.bool[builtins.bool]"  [arg-type]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("bytes" and "integer[Any]")  [operator]
- freqtrade/data/converter/orderflow.py:175: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "date"; expected "complex | number[Any, int | float | complex] | numpy.bool[builtins.bool]"  [arg-type]
- freqtrade/data/converter/orderflow.py:175: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "datetime"; expected "complex | number[Any, int | float | complex] | numpy.bool[builtins.bool]"  [arg-type]
- freqtrade/data/converter/orderflow.py:175: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "timedelta"; expected "complex | number[Any, int | float | complex] | numpy.bool[builtins.bool]"  [arg-type]
- freqtrade/data/converter/orderflow.py:175: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Timestamp"; expected "complex | number[Any, int | float | complex] | numpy.bool[builtins.bool]"  [arg-type]
- freqtrade/data/converter/orderflow.py:175: error: Argument 1 to "__call__" of "_NumberOp" has incompatible type "Timedelta"; expected "complex | number[Any, int | float | complex] | numpy.bool[builtins.bool]"  [arg-type]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("integer[Any]" and "str")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("integer[Any]" and "bytes")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("integer[Any]" and "date")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("integer[Any]" and "datetime")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("integer[Any]" and "timedelta")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("integer[Any]" and "Timestamp")  [operator]
+ freqtrade/data/converter/orderflow.py:175: error: Unsupported operand types for - ("integer[Any]" and "Timedelta")  [operator]

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ pandas-stubs/_libs/tslibs/period.pyi:167: error: Unused "type: ignore" comment  [unused-ignore]

colour (https://github.com/colour-science/colour)
- colour/continuous/signal.py:838: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "Buffer"  [call-overload]
+ colour/continuous/signal.py:838: error: No overload variant of "__le__" of "number" matches argument type "Buffer"  [operator]
- colour/continuous/signal.py:838: note:     def __call__(self, complex | number[Any, int | float | complex] | numpy.bool[builtins.bool], /) -> numpy.bool[builtins.bool]
+ colour/continuous/signal.py:838: note:     def __le__(self, complex | number[Any, int | float | complex] | numpy.bool[builtins.bool], /) -> numpy.bool[builtins.bool]
- colour/continuous/signal.py:838: note:     def __call__(self, _SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]]] | complex | _NestedSequence[complex], /) -> ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]]
+ colour/continuous/signal.py:838: note:     def __le__(self, _SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]]] | complex | _NestedSequence[complex] | _NestedSequence[_SupportsGE], /) -> ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]]
- colour/continuous/signal.py:838: note:     def __call__(self, _NestedSequence[_SupportsGE], /) -> ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]]
- colour/continuous/signal.py:838: note:     def __call__(self, _SupportsGE, /) -> numpy.bool[builtins.bool]
+ colour/continuous/signal.py:838: note:     def __le__(self, _SupportsGE, /) -> numpy.bool[builtins.bool]
- colour/continuous/signal.py:838: error: Argument 1 to "__call__" of "_ComparisonOpLE" has incompatible type "_NestedSequence[complex | bytes | str]"; expected "_SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]]] | complex | _NestedSequence[complex]"  [arg-type]
+ colour/continuous/signal.py:838: error: Unsupported operand types for <= ("floating[_16Bit]" and "_NestedSequence[complex | bytes | str]")  [operator]
+ colour/continuous/signal.py:838: error: Unsupported operand types for <= ("floating[_32Bit]" and "_NestedSequence[complex | bytes | str]")  [operator]
+ colour/continuous/signal.py:838: error: Unsupported operand types for <= ("float64" and "_NestedSequence[complex | bytes | str]")  [operator]
- colour/continuous/signal.py:838: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "slice[Any, Any, Any]"  [call-overload]
+ colour/continuous/signal.py:838: error: No overload variant of "__le__" of "number" matches argument type "slice[Any, Any, Any]"  [operator]
- colour/continuous/signal.py:839: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "Buffer"  [call-overload]
+ colour/continuous/signal.py:839: error: No overload variant of "__ge__" of "number" matches argument type "Buffer"  [operator]
- colour/continuous/signal.py:839: note:     def __call__(self, complex | number[Any, int | float | complex] | numpy.bool[builtins.bool], /) -> numpy.bool[builtins.bool]
+ colour/continuous/signal.py:839: note:     def __ge__(self, complex | number[Any, int | float | complex] | numpy.bool[builtins.bool], /) -> numpy.bool[builtins.bool]
- colour/continuous/signal.py:839: note:     def __call__(self, _SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]]] | complex | _NestedSequence[complex], /) -> ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]]
+ colour/continuous/signal.py:839: note:     def __ge__(self, _SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]]] | complex | _NestedSequence[complex] | _NestedSequence[_SupportsLE], /) -> ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]]
- colour/continuous/signal.py:839: note:     def __call__(self, _NestedSequence[_SupportsGT], /) -> ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]]
- colour/continuous/signal.py:839: note:     def __call__(self, _SupportsGT, /) -> numpy.bool[builtins.bool]
+ colour/continuous/signal.py:839: note:     def __ge__(self, _SupportsLE, /) -> numpy.bool[builtins.bool]
- colour/continuous/signal.py:839: error: Argument 1 to "__call__" of "_ComparisonOpGE" has incompatible type "_NestedSequence[complex | bytes | str]"; expected "_SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool] | number[Any, int | float | complex]]]] | complex | _NestedSequence[complex]"  [arg-type]
+ colour/continuous/signal.py:839: error: Unsupported operand types for >= ("floating[_16Bit]" and "_NestedSequence[complex | bytes | str]")  [operator]
+ colour/continuous/signal.py:839: error: Unsupported operand types for >= ("floating[_32Bit]" and "_NestedSequence[complex | bytes | str]")  [operator]
+ colour/continuous/signal.py:839: error: Unsupported operand types for >= ("float64" and "_NestedSequence[complex | bytes | str]")  [operator]
- colour/continuous/signal.py:839: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "slice[Any, Any, Any]"  [call-overload]
+ colour/continuous/signal.py:839: error: No overload variant of "__ge__" of "number" matches argument type "slice[Any, Any, Any]"  [operator]

@jorenham
Copy link
Member Author

jorenham commented Sep 7, 2025

The mypy_primer diffs might look problematic at first glance, but they're actually good news.

In case of jax and pandas-stubs, it allows them to remove some # type: ignore comments, which suggests that this fixes something that used to be broken.

The ffreqtrade diff applies to a single line, and is caused by mypy now reporting a different error code (operator instead of arg-type).
It's similar for colour, where the error code changed from call-overload to operator, which affects two lines.
Changes in error codes typically don't affect CI, so they probably won't even notice it.

@jorenham jorenham added the 09 - Backport-Candidate PRs tagged should be backported label Sep 7, 2025
@jorenham jorenham marked this pull request as ready for review September 7, 2025 18:49
signedinteger,
unsignedinteger,
)
from numpy import complex128, complexfloating, float64, floating, integer

Copy link
Member

Choose a reason for hiding this comment

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

The integer types are moved?

Copy link
Member Author

@jorenham jorenham Sep 9, 2025

Choose a reason for hiding this comment

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

ruff removed those because they weren't being used anymore

@charris charris merged commit f579bee into numpy:main Sep 9, 2025
83 of 84 checks passed
@charris
Copy link
Member

charris commented Sep 9, 2025

Thanks Joren.

@jorenham jorenham deleted the typing/inline-integer.methods branch September 9, 2025 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
09 - Backport-Candidate PRs tagged should be backported 41 - Static typing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants