Rely on typeshed/stubs for slice typing#21401
Open
ilevkivskyi wants to merge 2 commits intopython:masterfrom
Open
Rely on typeshed/stubs for slice typing#21401ilevkivskyi wants to merge 2 commits intopython:masterfrom
ilevkivskyi wants to merge 2 commits intopython:masterfrom
Conversation
Member
Author
|
cc @Dr-Irv |
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: sympy (https://github.com/sympy/sympy)
+ sympy/stats/stochastic_process_types.py:1255: error: Unused "type: ignore" comment [unused-ignore]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/tests/indexes/string/test_indexing.py:152: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:153: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:154: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:155: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:156: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:157: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:159: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:160: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:161: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:162: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:163: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:164: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:165: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:166: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/indexes/string/test_indexing.py:167: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/copy_view/test_indexing.py:410: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/copy_view/test_indexing.py:478: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/copy_view/test_indexing.py:480: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/copy_view/test_indexing.py:482: error: Unused "type: ignore" comment [unused-ignore]
+ pandas/tests/copy_view/test_indexing.py:485: error: Unused "type: ignore" comment [unused-ignore]
xarray (https://github.com/pydata/xarray)
+ xarray/tests/test_dataarray.py:1327: error: Unused "type: ignore" comment [unused-ignore]
+ xarray/tests/test_dataarray.py:1346: error: Unused "type: ignore" comment [unused-ignore]
freqtrade (https://github.com/freqtrade/freqtrade)
- freqtrade/strategy/strategy_helper.py:107: error: Slice index must be an integer, SupportsIndex or None [misc]
- freqtrade/strategy/strategy_helper.py:108: error: Slice index must be an integer, SupportsIndex or None [misc]
- freqtrade/data/btanalysis/trade_parallelism.py:119: error: Slice index must be an integer, SupportsIndex or None [misc]
- freqtrade/data/btanalysis/trade_parallelism.py:120: error: Slice index must be an integer, SupportsIndex or None [misc]
- freqtrade/data/btanalysis/trade_parallelism.py:135: error: Slice index must be an integer, SupportsIndex or None [misc]
- freqtrade/data/btanalysis/trade_parallelism.py:136: error: Invalid index type "tuple[slice[Timestamp, str | bytes | date | timedelta | datetime64[date | int | None] | <7 more items> | None, None], str]" for "_LocIndexerFrame[DataFrame]"; expected type "tuple[int | str | str_ | Timestamp | tuple[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...] | Callable[[DataFrame], Never], int | str | str_ | tuple[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...]]" [index]
- freqtrade/data/btanalysis/trade_parallelism.py:136: error: Invalid index type "tuple[slice[Timestamp, str | bytes | date | timedelta | datetime64[date | int | None] | <7 more items> | None, None], str]" for "_LocIndexerFrame[DataFrame]"; expected type "tuple[tuple[IndexOpsMixin[Any, Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any] | Sequence[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] | slice[Any, Any, Any], ...], Hashable]" [index]
- freqtrade/data/btanalysis/trade_parallelism.py:136: error: Slice index must be an integer, SupportsIndex or None [misc]
- freqtrade/data/btanalysis/trade_parallelism.py:151: error: Slice index must be an integer, SupportsIndex or None [misc]
- freqtrade/data/btanalysis/trade_parallelism.py:152: error: Invalid index type "tuple[slice[Timestamp, str | bytes | date | timedelta | datetime64[date | int | None] | <7 more items> | None, None], str]" for "_LocIndexerFrame[DataFrame]"; expected type "tuple[int | str | str_ | Timestamp | tuple[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...] | Callable[[DataFrame], Never], int | str | str_ | tuple[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any], ...]]" [index]
- freqtrade/data/btanalysis/trade_parallelism.py:152: error: Invalid index type "tuple[slice[Timestamp, str | bytes | date | timedelta | datetime64[date | int | None] | <7 more items> | None, None], str]" for "_LocIndexerFrame[DataFrame]"; expected type "tuple[tuple[IndexOpsMixin[Any, Any] | Series[builtins.bool] | ndarray[tuple[Any, ...], dtype[numpy.bool[builtins.bool]]] | list[builtins.bool] | str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any] | Sequence[str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]] | slice[Any, Any, Any], ...], Hashable]" [index]
- freqtrade/data/btanalysis/trade_parallelism.py:152: error: Slice index must be an integer, SupportsIndex or None [misc]
|
Member
Author
|
|
hauntsaninja
approved these changes
May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2410
slicehas been generic in typeshed for more than a year now. Also all builtin collections have preciseslice[SupportsIndex | None]types for__getitem__(). So, I don't think we need to be "policing"sliceanymore, it should be really responsibility of the stub maintainers now.After some searching, I see there are still many plain
sliceannotations in the wild, so this will be a trade-off of false positives to false negatives, but I think this is a right trade-off, since status quo causes issues for pandas dataframes and similar APIs.I also considered some "intermediate" solutions, where we would still enforce
SupportsIndexin some situations, but can't find anything that wouldn't be overly complicated.