Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make slice generic#11637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
srittau merged 19 commits intopython:mainfromSachaa-Thanasius:generic-slice
Oct 24, 2024
Merged

Make slice generic#11637

srittau merged 19 commits intopython:mainfromSachaa-Thanasius:generic-slice
Oct 24, 2024

Conversation

@Sachaa-Thanasius
Copy link
Contributor

@Sachaa-ThanasiusSachaa-Thanasius commentedMar 20, 2024
edited by srittau
Loading

Mainly doing this out of curiosity to see the primer hits.

EDIT: Wouldclose#8647.

jorenham and lorenzo-w reacted with heart emoji
@github-actions

This comment has been minimized.

@JelleZijlstra
Copy link
Member

cc@cdce8p I think the primer hits suggest a mypy bug where it looks up "_StartT" in the wrong scope.

AlexWaygood reacted with thumbs up emoji

@cdce8p
Copy link
Contributor

cc@cdce8p I think the primer hits suggest a mypy bug where it looks up "_StartT" in the wrong scope.

Recursive TypeVar defaults was one of the things that didn't make it into1.9.0 unfortunately. I did do some work on it already, but that isn't released yet:python/mypy#16878. Don't know if it's enough forslice yet though.

If you're interested, maybe that's also something for@AlexWaygood, a few weeks back I created a custom repo to upload dev releases of mypy to PyPI under themypy-dev project name. They always track a mypy commit upstream and are great to test / use the lasted version (even in production if you feel like it).mypy --version still works as expected. I originally created it as it was unclear when1.9.0 would actually be released. In the past the release frequency was also a bit more unpredictable.

https://github.com/cdce8p/mypy-dev
https://github.com/cdce8p/mypy-dev/releases

AlexWaygood reacted with heart emoji

@Sachaa-Thanasius
Copy link
ContributorAuthor

I just assumed my attempt at implementation was wrong and gave up. Should this be reopened, then?

@JelleZijlstra
Copy link
Member

Thanks@cdce8p, I forgot that PR didn't make it into 1.9. Hopefully we'll have another release soon. Your mypy-dev project is interesting; maybe that's even something we could do on mypy itself. For example, we could have a weekly cron job uploading alpha releases.

@Sachaa-Thanasius I think we may be able to merge this PR after mypy 1.10 is released (when that will happen, I don't know). You can leave it open in the meantime and mark it as deferred. With some hackery it may be possible to point typeshed's CI at the mypy master branch so we can test earlier whether everything works as expected.

@Sachaa-Thanasius
Copy link
ContributorAuthor

Understood. Should slice be changed in the runtime cpython as well to support__class_getitem__ viaGenericAlias, or is this purely meant to be a typeshed thing? Not something I considered when originally opening this, but now that this actually has a chance of going somewhere . . .

@Sachaa-Thanasius
Copy link
ContributorAuthor

Also, sidenote: The pyright errors specifically forslice.stop and and the first overload ofslice.__new__ (with text like the following) are the result of a bug that was fixedearlier today, I think:

Type parameter "_StopT" has a default type that refers to one or more type variables that are out of scope    Type variable "_StartT" is not in scope

@github-actions

This comment has been minimized.

@cdce8p
Copy link
Contributor

cdce8p commentedMar 21, 2024
edited
Loading

With some hackery it may be possible to point typeshed's CI at the mypy master branch so we can test earlier whether everything works as expected.

@Sachaa-Thanasius You could try to replace the mypy version listed inrequirements-tests.txt.

-mypy==1.9.0+mypy-dev==1.10.0a2

That release trackspython/mypy@b013cc0 which was commited fairly recently to mypy master (5 days ago).

Update: Seems like the mypy primer doesn't work for it, unfortunately.

Sachaa-Thanasius reacted with thumbs up emoji

@srittausrittau added the status: deferredIssue or PR deferred until some precondition is fixed labelMar 21, 2024
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@Sachaa-Thanasius
Copy link
ContributorAuthor

Sachaa-Thanasius commentedApr 24, 2024
edited
Loading

Well, that's far more promising than before. Still not sure if this needs to be reflected in cpython by adding a__class_getitem__ to slice.

@srittausrittau removed the status: deferredIssue or PR deferred until some precondition is fixed labelApr 24, 2024
@srittau
Copy link
Collaborator

I've removed the Deferred label. I've just looked at spark primer output. The problem is on their side, since they reuse thestart variable for different types.

Sachaa-Thanasius reacted with thumbs up emoji

@Sachaa-Thanasius
Copy link
ContributorAuthor

Sachaa-Thanasius commentedApr 24, 2024
edited
Loading

The error that pyright is hitting is that the usage ofitertools.starmap doesn't resolve the types ofslice.

# Truncated setup.fromcollections.abcimportIterator,Sequencefromitertoolsimportcombinations,repeat,starmapfromoperatorimportgetitemfromtypingimportTypeVar,cast_T=TypeVar("_T")# Actual functiondefsubslices(seq:Sequence[_T])->Iterator[Sequence[_T]]:slices=starmap(slice,combinations(range(len(seq)+1),2))reveal_type(slices)# Type of "slices" is "starmap[slice[_StartT@slice, _StopT@slice, _StepT@slice]]"# Adding this cast removes the error on the final line:# slices = cast(starmap[slice[int, int, int | None]], slices)# And using a generator instead of starmap removes the error on the final line as well:# slices = (slice(*args) for args in combinations(range(len(seq) + 1), 2))returnmap(getitem,repeat(seq),slices)# Long error.

Full playground examplehere to recreate the conditions of the error.

Might be more of a deficiency in the typing ofstarmap (or something else with pyright’s analysis) than anything withslice. Not sure how to fix it though.

@hamdanal
Copy link
Contributor

I might be missing something obvious but it is not clear to me why the type ofstop has to default to the type ofstart. At runtimestart isNone if it is not passed to the constructor:

$cat t.pyfrom typing_extensions import reveal_types = slice(10)reveal_type(s)reveal_type(s.start)reveal_type(s.stop)reveal_type(s.step)$python t.pyRuntime type is 'slice'Runtime type is 'NoneType'Runtime type is 'int'Runtime type is 'NoneType'

Similarly, the type ofstep should default toNone.

So I would expect the definitions of the type variables to be:

_StartT=TypeVar("_StartT",default=None)_StopT=TypeVar("_StopT",default=int)_StepT=TypeVar("_StepT",default=None)
Gobot1234 reacted with thumbs up emoji

@Sachaa-Thanasius
Copy link
ContributorAuthor

Sachaa-Thanasius commentedMay 3, 2024
edited
Loading

I won’t lie; I just copy-pasted the example implementation from PEP 696 without much thought, since this PR wasn’t originally opened with the intention of being merged. Haven’t double-checked since. Definitely will take another look though.

@github-actions
Copy link
Contributor

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

prefect (https://github.com/PrefectHQ/prefect)- src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice, /) -> tuple[Never, ...]+ src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice[Any, Any, Any], /) -> tuple[Never, ...]- src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice, /) -> Sequence[Never]+ src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice[Any, Any, Any], /) -> Sequence[Never]- src/prefect/cli/cloud/__init__.py:326: note:     def __getitem__(self, SupportsIndex | slice, /) -> str+ src/prefect/cli/cloud/__init__.py:326: note:     def __getitem__(self, SupportsIndex | slice[Any, Any, Any], /) -> str- src/prefect/cli/deploy.py:1132: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1132: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1158: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1158: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1166: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1166: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1183: note:     def __getitem__(self, slice, /) -> list[dict[Any, Any]]+ src/prefect/cli/deploy.py:1183: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[Any, Any]]werkzeug (https://github.com/pallets/werkzeug)- tests/test_wrappers.py:522: note:     def __setitem__(self, slice, Iterable[tuple[str, str]], /) -> None+ tests/test_wrappers.py:522: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[tuple[str, str]], /) -> None- tests/test_wrappers.py:563: note:     def __setitem__(self, slice, Iterable[tuple[str, str]], /) -> None+ tests/test_wrappers.py:563: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[tuple[str, str]], /) -> Nonestreamlit (https://github.com/streamlit/streamlit)- lib/tests/streamlit/elements/lib/column_config_utils_test.py:385:13: note:     def __getitem__(self, Union[SupportsIndex, slice], /) -> str+ lib/tests/streamlit/elements/lib/column_config_utils_test.py:385:13: note:     def __getitem__(self, Union[SupportsIndex, slice[Any, Any, Any]], /) -> str- lib/tests/streamlit/runtime/state/query_params_test.py:264:37: note:         def __getitem__(self, slice, /) -> Tuple[Any, ...]+ lib/tests/streamlit/runtime/state/query_params_test.py:264:37: note:         def __getitem__(self, slice[Any, Any, Any], /) -> Tuple[Any, ...]ibis (https://github.com/ibis-project/ibis)- ibis/selectors.py:678: error: Incompatible types in assignment (expression has type "Slice", variable has type "str | int | slice | Iterable[int | str]")  [assignment]+ ibis/selectors.py:678: error: Incompatible types in assignment (expression has type "Slice", variable has type "str | int | slice[Any, Any, Any] | Iterable[int | str]")  [assignment]- ibis/selectors.py:679: error: Argument 1 to "ColumnIndex" has incompatible type "int | slice | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]"  [arg-type]+ ibis/selectors.py:679: error: Argument 1 to "ColumnIndex" has incompatible type "int | slice[None, Any, None] | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]"  [arg-type]- ibis/expr/types/arrays.py:147: error: Argument 2 to "ArraySlice" has incompatible type "Any | int"; expected "Value[Integer, Any]"  [arg-type]+ ibis/expr/types/arrays.py:147: error: Argument 2 to "ArraySlice" has incompatible type "int"; expected "Value[Integer, Any]"  [arg-type]speedrun.com_global_scoreboard_webapp (https://github.com/Avasam/speedrun.com_global_scoreboard_webapp)- backend/api/tournament_scheduler_api.py:327: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:327: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]- backend/api/tournament_scheduler_api.py:331: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:331: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]- backend/api/tournament_scheduler_api.py:335: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:335: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]pandas (https://github.com/pandas-dev/pandas)+ pandas/core/array_algos/transforms.py:41: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/array_algos/transforms.py:43: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1387: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1387: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1387: error: Argument 2 to "slice" has incompatible type "None"; expected "int"  [arg-type]+ pandas/core/algorithms.py:1398: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1398: error: Argument 1 to "slice" has incompatible type "None"; expected "int"  [arg-type]+ pandas/core/algorithms.py:1398: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1402: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1402: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1402: error: Argument 2 to "slice" has incompatible type "None"; expected "int"  [arg-type]+ pandas/core/indexes/multi.py:2501: error: No overload variant of "range" matches argument types "None", "Any", "int"  [call-overload]+ pandas/core/indexes/multi.py:2501: note: Possible overload variants:+ pandas/core/indexes/multi.py:2501: note:     def __new__(cls, SupportsIndex, /) -> range+ pandas/core/indexes/multi.py:2501: note:     def __new__(cls, SupportsIndex, SupportsIndex, SupportsIndex = ..., /) -> range+ pandas/core/indexes/multi.py:3490: error: "int" has no attribute "step"  [attr-defined]+ pandas/core/indexes/multi.py:3536: error: Incompatible types in assignment (expression has type "ndarray[Any, dtype[signedinteger[Any]]] | signedinteger[Any]", variable has type "int")  [assignment]+ pandas/core/indexes/base.py:6690: error: Incompatible return value type (got "None", expected "int")  [return-value]spark (https://github.com/apache/spark)+ python/pyspark/sql/classic/column.py:414: error: Argument 1 to "substr" of "Column" has incompatible type "None"; expected "int | Column"  [arg-type]+ python/pyspark/sql/connect/column.py:552: error: Argument 1 to "substr" of "Column" has incompatible type "None"; expected "int | Column"  [arg-type]scipy (https://github.com/scipy/scipy)+ scipy/optimize/_isotonic.py:125: error: Argument 3 to "slice" has incompatible type "int"; expected "None"  [arg-type]freqtrade (https://github.com/freqtrade/freqtrade)+ freqtrade/exchange/exchange.py:2901: error: Argument 1 to "slice" has incompatible type "None"; expected "int"  [arg-type]discord.py (https://github.com/Rapptz/discord.py)- discord/http.py:233: note:     def __setitem__(self, slice, Iterable[Embed], /) -> None+ discord/http.py:233: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[Embed], /) -> Nonejax (https://github.com/google/jax)+ jax/_src/numpy/lax_numpy.py:715: error: Argument 3 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/_src/numpy/lax_numpy.py:1785: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/_src/numpy/lax_numpy.py:1786: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1990: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1990: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1990: error: Argument 3 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1991: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1991: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1991: error: Argument 3 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1995: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1995: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1995: error: Argument 3 to "slice" has incompatible type "int"; expected "None"  [arg-type]xarray (https://github.com/pydata/xarray)+ xarray/core/dataset.py: note: In member "tail" of class "Dataset":+ xarray/core/dataset.py:3412: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ xarray/core/dataset.py: note: At top level:+ xarray/core/dataset.py: note: In member "diff" of class "Dataset":+ xarray/core/dataset.py:7957: error: Incompatible types in assignment (expression has type "dict[Hashable, slice[None, int, None]]", variable has type "dict[Hashable, slice[int, None, None]]")  [assignment]+ xarray/core/dataset.py: note: At top level:+ xarray/tests/test_backends.py: note: In member "test_write_region_mode" of class "ZarrBase":+ xarray/tests/test_backends.py:3007: error: No overload variant of "to_zarr" of "Dataset" matches argument types "Any", "object", "Any", "dict[str, Any]"  [call-overload]+ xarray/tests/test_backends.py:3007: note: Possible overload variants:+ xarray/tests/test_backends.py:3007: note:     def to_zarr(self, store: MutableMapping[Any, Any] | str | PathLike[str] | None = ..., chunk_store: MutableMapping[Any, Any] | str | PathLike[Any] | None = ..., mode: Literal['w', 'w-', 'a', 'a-', 'r+', 'r'] | None = ..., synchronizer: Any = ..., group: str | None = ..., encoding: Mapping[Any, Any] | None = ..., *, compute: Literal[True] = ..., consolidated: bool | None = ..., append_dim: Hashable | None = ..., region: Mapping[str, slice[Any, Any, Any] | Literal['auto']] | Literal['auto'] | None = ..., safe_chunks: bool = ..., storage_options: dict[str, str] | None = ..., zarr_version: int | None = ..., zarr_format: int | None = ..., write_empty_chunks: bool | None = ..., chunkmanager_store_kwargs: dict[str, Any] | None = ...) -> ZarrStore+ xarray/tests/test_backends.py:3007: note:     def to_zarr(self, store: MutableMapping[Any, Any] | str | PathLike[str] | None = ..., chunk_store: MutableMapping[Any, Any] | str | PathLike[Any] | None = ..., mode: Literal['w', 'w-', 'a', 'a-', 'r+', 'r'] | None = ..., synchronizer: Any = ..., group: str | None = ..., encoding: Mapping[Any, Any] | None = ..., *, compute: Literal[False], consolidated: bool | None = ..., append_dim: Hashable | None = ..., region: Mapping[str, slice[Any, Any, Any] | Literal['auto']] | Literal['auto'] | None = ..., safe_chunks: bool = ..., storage_options: dict[str, str] | None = ..., zarr_version: int | None = ..., zarr_format: int | None = ..., write_empty_chunks: bool | None = ..., chunkmanager_store_kwargs: dict[str, Any] | None = ...) -> Any+ xarray/tests/test_backends.py:3007: error: Argument 1 to "isel" of "Dataset" has incompatible type "object"; expected "Mapping[Any, Any] | None"  [arg-type]operator (https://github.com/canonical/operator)- ops/framework.py:1304: note:          def __getitem__(self, slice, /) -> MutableSequence[Any]+ ops/framework.py:1304: note:          def __getitem__(self, slice[Any, Any, Any], /) -> MutableSequence[Any]- ops/framework.py:1304: note:          def __getitem__(self, slice, /) -> Sequence[Any]+ ops/framework.py:1304: note:          def __getitem__(self, slice[Any, Any, Any], /) -> Sequence[Any]- ops/framework.py:1307: note:          def __setitem__(self, slice, Iterable[Any], /) -> None+ ops/framework.py:1307: note:          def __setitem__(self, slice[Any, Any, Any], Iterable[Any], /) -> None- ops/framework.py:1311: note:          def __delitem__(self, slice, /) -> None+ ops/framework.py:1311: note:          def __delitem__(self, slice[Any, Any, Any], /) -> Nonecolour (https://github.com/colour-science/colour)- colour/continuous/signal.py:843: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "slice"  [call-overload]+ colour/continuous/signal.py:843: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "slice[Any, Any, Any]"  [call-overload]- colour/continuous/signal.py:844: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "slice"  [call-overload]+ colour/continuous/signal.py:844: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "slice[Any, Any, Any]"  [call-overload]pandas-stubs (https://github.com/pandas-dev/pandas-stubs)+ tests/test_frame.py:224: error: Expression is of type "Any", not "DataFrame"  [assert-type]+ tests/test_frame.py:225: error: Expression is of type "Any", not "DataFrame"  [assert-type]kornia (https://github.com/kornia/kornia)+ kornia/contrib/models/sam/architecture/mask_decoder.py:92: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]manticore (https://github.com/trailofbits/manticore)- tests/wasm/json2mc.py:103: note:     def __getitem__(self, slice, /) -> list[Any]+ tests/wasm/json2mc.py:103: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]+ manticore/native/memory.py:229: error: Unsupported operand types for <= ("int" and "None")  [operator]dd-trace-py (https://github.com/DataDog/dd-trace-py)- ddtrace/settings/config.py:888: note:     def __getitem__(self, SupportsIndex | slice, /) -> str+ ddtrace/settings/config.py:888: note:     def __getitem__(self, SupportsIndex | slice[Any, Any, Any], /) -> str

@github-actions
Copy link
Contributor

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

prefect (https://github.com/PrefectHQ/prefect)- src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice, /) -> tuple[Never, ...]+ src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice[Any, Any, Any], /) -> tuple[Never, ...]- src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice, /) -> Sequence[Never]+ src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice[Any, Any, Any], /) -> Sequence[Never]- src/prefect/cli/cloud/__init__.py:326: note:     def __getitem__(self, SupportsIndex | slice, /) -> str+ src/prefect/cli/cloud/__init__.py:326: note:     def __getitem__(self, SupportsIndex | slice[Any, Any, Any], /) -> str- src/prefect/cli/deploy.py:1132: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1132: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1158: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1158: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1166: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1166: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1183: note:     def __getitem__(self, slice, /) -> list[dict[Any, Any]]+ src/prefect/cli/deploy.py:1183: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[Any, Any]]werkzeug (https://github.com/pallets/werkzeug)- tests/test_wrappers.py:522: note:     def __setitem__(self, slice, Iterable[tuple[str, str]], /) -> None+ tests/test_wrappers.py:522: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[tuple[str, str]], /) -> None- tests/test_wrappers.py:563: note:     def __setitem__(self, slice, Iterable[tuple[str, str]], /) -> None+ tests/test_wrappers.py:563: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[tuple[str, str]], /) -> Nonestreamlit (https://github.com/streamlit/streamlit)- lib/tests/streamlit/elements/lib/column_config_utils_test.py:385:13: note:     def __getitem__(self, Union[SupportsIndex, slice], /) -> str+ lib/tests/streamlit/elements/lib/column_config_utils_test.py:385:13: note:     def __getitem__(self, Union[SupportsIndex, slice[Any, Any, Any]], /) -> str- lib/tests/streamlit/runtime/state/query_params_test.py:264:37: note:         def __getitem__(self, slice, /) -> Tuple[Any, ...]+ lib/tests/streamlit/runtime/state/query_params_test.py:264:37: note:         def __getitem__(self, slice[Any, Any, Any], /) -> Tuple[Any, ...]ibis (https://github.com/ibis-project/ibis)- ibis/selectors.py:678: error: Incompatible types in assignment (expression has type "Slice", variable has type "str | int | slice | Iterable[int | str]")  [assignment]+ ibis/selectors.py:678: error: Incompatible types in assignment (expression has type "Slice", variable has type "str | int | slice[Any, Any, Any] | Iterable[int | str]")  [assignment]- ibis/selectors.py:679: error: Argument 1 to "ColumnIndex" has incompatible type "int | slice | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]"  [arg-type]+ ibis/selectors.py:679: error: Argument 1 to "ColumnIndex" has incompatible type "int | slice[Any, Any, Any] | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]"  [arg-type]speedrun.com_global_scoreboard_webapp (https://github.com/Avasam/speedrun.com_global_scoreboard_webapp)- backend/api/tournament_scheduler_api.py:327: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:327: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]- backend/api/tournament_scheduler_api.py:331: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:331: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]- backend/api/tournament_scheduler_api.py:335: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:335: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]spark (https://github.com/apache/spark)+ python/pyspark/sql/classic/column.py:414: error: Argument 1 to "substr" of "Column" has incompatible type "Any | None"; expected "int | Column"  [arg-type]+ python/pyspark/sql/connect/column.py:552: error: Argument 1 to "substr" of "Column" has incompatible type "Any | None"; expected "int | Column"  [arg-type]pandas (https://github.com/pandas-dev/pandas)+ pandas/core/array_algos/transforms.py:41: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1387: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1387: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1387: error: Argument 2 to "slice" has incompatible type "None"; expected "int"  [arg-type]+ pandas/core/algorithms.py:1398: error: Argument 1 to "slice" has incompatible type "None"; expected "int"  [arg-type]+ pandas/core/algorithms.py:1398: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1402: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1402: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1402: error: Argument 2 to "slice" has incompatible type "None"; expected "int"  [arg-type]+ pandas/core/indexes/multi.py:2501: error: Argument 1 to "range" has incompatible type "Any | None"; expected "SupportsIndex"  [arg-type]+ pandas/core/indexes/base.py:6690: error: Incompatible return value type (got "Any | None", expected "int")  [return-value]discord.py (https://github.com/Rapptz/discord.py)- discord/http.py:233: note:     def __setitem__(self, slice, Iterable[Embed], /) -> None+ discord/http.py:233: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[Embed], /) -> Nonefreqtrade (https://github.com/freqtrade/freqtrade)+ freqtrade/exchange/exchange.py:2901: error: Argument 1 to "slice" has incompatible type "None"; expected "int"  [arg-type]xarray (https://github.com/pydata/xarray)+ xarray/core/dataset.py: note: In member "tail" of class "Dataset":+ xarray/core/dataset.py:3412: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ xarray/core/dataset.py: note: At top level:+ xarray/core/dataset.py: note: In member "diff" of class "Dataset":+ xarray/core/dataset.py:7957: error: Incompatible types in assignment (expression has type "dict[Hashable, slice[None, int, Any | None]]", variable has type "dict[Hashable, slice[int, None, Any | None]]")  [assignment]+ xarray/core/dataset.py: note: At top level:+ xarray/tests/test_backends.py: note: In member "test_write_region_mode" of class "ZarrBase":+ xarray/tests/test_backends.py:3007: error: No overload variant of "to_zarr" of "Dataset" matches argument types "Any", "object", "Any", "dict[str, Any]"  [call-overload]+ xarray/tests/test_backends.py:3007: note: Possible overload variants:+ xarray/tests/test_backends.py:3007: note:     def to_zarr(self, store: MutableMapping[Any, Any] | str | PathLike[str] | None = ..., chunk_store: MutableMapping[Any, Any] | str | PathLike[Any] | None = ..., mode: Literal['w', 'w-', 'a', 'a-', 'r+', 'r'] | None = ..., synchronizer: Any = ..., group: str | None = ..., encoding: Mapping[Any, Any] | None = ..., *, compute: Literal[True] = ..., consolidated: bool | None = ..., append_dim: Hashable | None = ..., region: Mapping[str, slice[Any, Any, Any] | Literal['auto']] | Literal['auto'] | None = ..., safe_chunks: bool = ..., storage_options: dict[str, str] | None = ..., zarr_version: int | None = ..., zarr_format: int | None = ..., write_empty_chunks: bool | None = ..., chunkmanager_store_kwargs: dict[str, Any] | None = ...) -> ZarrStore+ xarray/tests/test_backends.py:3007: note:     def to_zarr(self, store: MutableMapping[Any, Any] | str | PathLike[str] | None = ..., chunk_store: MutableMapping[Any, Any] | str | PathLike[Any] | None = ..., mode: Literal['w', 'w-', 'a', 'a-', 'r+', 'r'] | None = ..., synchronizer: Any = ..., group: str | None = ..., encoding: Mapping[Any, Any] | None = ..., *, compute: Literal[False], consolidated: bool | None = ..., append_dim: Hashable | None = ..., region: Mapping[str, slice[Any, Any, Any] | Literal['auto']] | Literal['auto'] | None = ..., safe_chunks: bool = ..., storage_options: dict[str, str] | None = ..., zarr_version: int | None = ..., zarr_format: int | None = ..., write_empty_chunks: bool | None = ..., chunkmanager_store_kwargs: dict[str, Any] | None = ...) -> Any+ xarray/tests/test_backends.py:3007: error: Argument 1 to "isel" of "Dataset" has incompatible type "object"; expected "Mapping[Any, Any] | None"  [arg-type]jax (https://github.com/google/jax)+ jax/_src/numpy/lax_numpy.py:1786: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1990: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1991: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1995: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]operator (https://github.com/canonical/operator)- ops/framework.py:1304: note:          def __getitem__(self, slice, /) -> MutableSequence[Any]+ ops/framework.py:1304: note:          def __getitem__(self, slice[Any, Any, Any], /) -> MutableSequence[Any]- ops/framework.py:1304: note:          def __getitem__(self, slice, /) -> Sequence[Any]+ ops/framework.py:1304: note:          def __getitem__(self, slice[Any, Any, Any], /) -> Sequence[Any]- ops/framework.py:1307: note:          def __setitem__(self, slice, Iterable[Any], /) -> None+ ops/framework.py:1307: note:          def __setitem__(self, slice[Any, Any, Any], Iterable[Any], /) -> None- ops/framework.py:1311: note:          def __delitem__(self, slice, /) -> None+ ops/framework.py:1311: note:          def __delitem__(self, slice[Any, Any, Any], /) -> Nonecolour (https://github.com/colour-science/colour)- colour/continuous/signal.py:843: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "slice"  [call-overload]+ colour/continuous/signal.py:843: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "slice[Any, Any, Any]"  [call-overload]- colour/continuous/signal.py:844: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "slice"  [call-overload]+ colour/continuous/signal.py:844: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "slice[Any, Any, Any]"  [call-overload]pandas-stubs (https://github.com/pandas-dev/pandas-stubs)+ tests/test_frame.py:224: error: Expression is of type "Any", not "DataFrame"  [assert-type]+ tests/test_frame.py:225: error: Expression is of type "Any", not "DataFrame"  [assert-type]kornia (https://github.com/kornia/kornia)+ kornia/contrib/models/sam/architecture/mask_decoder.py:92: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]dd-trace-py (https://github.com/DataDog/dd-trace-py)- ddtrace/settings/config.py:888: note:     def __getitem__(self, SupportsIndex | slice, /) -> str+ ddtrace/settings/config.py:888: note:     def __getitem__(self, SupportsIndex | slice[Any, Any, Any], /) -> strmanticore (https://github.com/trailofbits/manticore)- tests/wasm/json2mc.py:103: note:     def __getitem__(self, slice, /) -> list[Any]+ tests/wasm/json2mc.py:103: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]+ manticore/native/memory.py:229: error: Unsupported operand types for <= ("int" and "None")  [operator]+ manticore/native/memory.py:229: note: Left operand is of type "Any | None"

@github-actions
Copy link
Contributor

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

werkzeug (https://github.com/pallets/werkzeug)- tests/test_wrappers.py:522: note:     def __setitem__(self, slice, Iterable[tuple[str, str]], /) -> None+ tests/test_wrappers.py:522: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[tuple[str, str]], /) -> None- tests/test_wrappers.py:563: note:     def __setitem__(self, slice, Iterable[tuple[str, str]], /) -> None+ tests/test_wrappers.py:563: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[tuple[str, str]], /) -> Noneprefect (https://github.com/PrefectHQ/prefect)- src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice, /) -> tuple[Never, ...]+ src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice[Any, Any, Any], /) -> tuple[Never, ...]- src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice, /) -> Sequence[Never]+ src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice[Any, Any, Any], /) -> Sequence[Never]- src/prefect/cli/cloud/__init__.py:326: note:     def __getitem__(self, SupportsIndex | slice, /) -> str+ src/prefect/cli/cloud/__init__.py:326: note:     def __getitem__(self, SupportsIndex | slice[Any, Any, Any], /) -> str- src/prefect/cli/deploy.py:1132: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1132: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1158: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1158: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1166: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1166: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1183: note:     def __getitem__(self, slice, /) -> list[dict[Any, Any]]+ src/prefect/cli/deploy.py:1183: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[Any, Any]]streamlit (https://github.com/streamlit/streamlit)- lib/tests/streamlit/elements/lib/column_config_utils_test.py:385:13: note:     def __getitem__(self, Union[SupportsIndex, slice], /) -> str+ lib/tests/streamlit/elements/lib/column_config_utils_test.py:385:13: note:     def __getitem__(self, Union[SupportsIndex, slice[Any, Any, Any]], /) -> str- lib/tests/streamlit/runtime/state/query_params_test.py:264:37: note:         def __getitem__(self, slice, /) -> Tuple[Any, ...]+ lib/tests/streamlit/runtime/state/query_params_test.py:264:37: note:         def __getitem__(self, slice[Any, Any, Any], /) -> Tuple[Any, ...]speedrun.com_global_scoreboard_webapp (https://github.com/Avasam/speedrun.com_global_scoreboard_webapp)- backend/api/tournament_scheduler_api.py:327: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:327: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]- backend/api/tournament_scheduler_api.py:331: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:331: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]- backend/api/tournament_scheduler_api.py:335: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:335: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]ibis (https://github.com/ibis-project/ibis)- ibis/selectors.py:678: error: Incompatible types in assignment (expression has type "Slice", variable has type "str | int | slice | Iterable[int | str]")  [assignment]+ ibis/selectors.py:678: error: Incompatible types in assignment (expression has type "Slice", variable has type "str | int | slice[Any, Any, Any] | Iterable[int | str]")  [assignment]- ibis/selectors.py:679: error: Argument 1 to "ColumnIndex" has incompatible type "int | slice | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]"  [arg-type]+ ibis/selectors.py:679: error: Argument 1 to "ColumnIndex" has incompatible type "int | slice[Any, Any, Any] | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]"  [arg-type]pandas (https://github.com/pandas-dev/pandas)+ pandas/core/array_algos/transforms.py:41: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1387: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1387: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1387: error: Argument 2 to "slice" has incompatible type "None"; expected "int"  [arg-type]+ pandas/core/algorithms.py:1398: error: Argument 1 to "slice" has incompatible type "None"; expected "int"  [arg-type]+ pandas/core/algorithms.py:1398: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1402: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1402: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ pandas/core/algorithms.py:1402: error: Argument 2 to "slice" has incompatible type "None"; expected "int"  [arg-type]discord.py (https://github.com/Rapptz/discord.py)- discord/http.py:233: note:     def __setitem__(self, slice, Iterable[Embed], /) -> None+ discord/http.py:233: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[Embed], /) -> Nonefreqtrade (https://github.com/freqtrade/freqtrade)+ freqtrade/exchange/exchange.py:2901: error: Argument 1 to "slice" has incompatible type "None"; expected "int"  [arg-type]xarray (https://github.com/pydata/xarray)+ xarray/core/dataset.py: note: In member "tail" of class "Dataset":+ xarray/core/dataset.py:3412: error: Argument 1 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ xarray/core/dataset.py: note: At top level:+ xarray/core/dataset.py: note: In member "diff" of class "Dataset":+ xarray/core/dataset.py:7957: error: Incompatible types in assignment (expression has type "dict[Hashable, slice[None, int, Any]]", variable has type "dict[Hashable, slice[int, None, Any]]")  [assignment]+ xarray/core/dataset.py: note: At top level:jax (https://github.com/google/jax)+ jax/_src/numpy/lax_numpy.py:1786: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1990: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1991: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]+ jax/experimental/sparse/bcoo.py:1995: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]operator (https://github.com/canonical/operator)- ops/framework.py:1304: note:          def __getitem__(self, slice, /) -> MutableSequence[Any]+ ops/framework.py:1304: note:          def __getitem__(self, slice[Any, Any, Any], /) -> MutableSequence[Any]- ops/framework.py:1304: note:          def __getitem__(self, slice, /) -> Sequence[Any]+ ops/framework.py:1304: note:          def __getitem__(self, slice[Any, Any, Any], /) -> Sequence[Any]- ops/framework.py:1307: note:          def __setitem__(self, slice, Iterable[Any], /) -> None+ ops/framework.py:1307: note:          def __setitem__(self, slice[Any, Any, Any], Iterable[Any], /) -> None- ops/framework.py:1311: note:          def __delitem__(self, slice, /) -> None+ ops/framework.py:1311: note:          def __delitem__(self, slice[Any, Any, Any], /) -> Nonecolour (https://github.com/colour-science/colour)- colour/continuous/signal.py:843: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "slice"  [call-overload]+ colour/continuous/signal.py:843: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "slice[Any, Any, Any]"  [call-overload]- colour/continuous/signal.py:844: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "slice"  [call-overload]+ colour/continuous/signal.py:844: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "slice[Any, Any, Any]"  [call-overload]pandas-stubs (https://github.com/pandas-dev/pandas-stubs)+ tests/test_frame.py:224: error: Expression is of type "Any", not "DataFrame"  [assert-type]+ tests/test_frame.py:225: error: Expression is of type "Any", not "DataFrame"  [assert-type]kornia (https://github.com/kornia/kornia)+ kornia/contrib/models/sam/architecture/mask_decoder.py:92: error: Argument 2 to "slice" has incompatible type "int"; expected "None"  [arg-type]dd-trace-py (https://github.com/DataDog/dd-trace-py)- ddtrace/settings/config.py:888: note:     def __getitem__(self, SupportsIndex | slice, /) -> str+ ddtrace/settings/config.py:888: note:     def __getitem__(self, SupportsIndex | slice[Any, Any, Any], /) -> strmanticore (https://github.com/trailofbits/manticore)- tests/wasm/json2mc.py:103: note:     def __getitem__(self, slice, /) -> list[Any]+ tests/wasm/json2mc.py:103: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]

@AlexWaygood
Copy link
Member

I fixed the failing test using@hamdanal's excellent suggestion and merged inmain. Now it's just a matter of figuring out whether the new primer hits are acceptable or not.@srittau analysed a bunch of these in#11637 (comment), but there seem to be some new ones now.freqtrade andxarray aren't too concerning; these are places where users will have to add explicit annotations, but it's not so awful. These are a bit concerning to me, however:

pandas-stubs (https://github.com/pandas-dev/pandas-stubs)+ tests/test_frame.py:224: error: Expression is of type "Any", not "DataFrame"  [assert-type]+ tests/test_frame.py:225: error: Expression is of type "Any", not "DataFrame"  [assert-type]

The failingassert_type calls arehere. I'm not sure I understand why mypy is now inferringAny fordf[1:], as this should be covered by the second overload forDataFrame.__getitem__here, which accepts a union includingslice and returnsDataFrame.

@JukkaL
Copy link
Contributor

If you can narrow down some false positives to a mypy bug, it would help if you can file a mypy issue and include a link to this PR.

AlexWaygood reacted with thumbs up emoji

@github-actions
Copy link
Contributor

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

prefect (https://github.com/PrefectHQ/prefect)- src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice, /) -> tuple[Never, ...]+ src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice[int | Any, int | Any, int | Any], /) -> tuple[Never, ...]- src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice, /) -> Sequence[Never]+ src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice[int | Any, int | Any, int | Any], /) -> Sequence[Never]- src/prefect/cli/cloud/__init__.py:326: note:     def __getitem__(self, SupportsIndex | slice, /) -> str+ src/prefect/cli/cloud/__init__.py:326: note:     def __getitem__(self, SupportsIndex | slice[int | Any, int | Any, int | Any], /) -> str- src/prefect/cli/deploy.py:1132: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1132: note:     def __setitem__(self, slice[int | Any, int | Any, int | Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1158: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1158: note:     def __setitem__(self, slice[int | Any, int | Any, int | Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1166: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1166: note:     def __setitem__(self, slice[int | Any, int | Any, int | Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1183: note:     def __getitem__(self, slice, /) -> list[dict[Any, Any]]+ src/prefect/cli/deploy.py:1183: note:     def __getitem__(self, slice[int | Any, int | Any, int | Any], /) -> list[dict[Any, Any]]werkzeug (https://github.com/pallets/werkzeug)- tests/test_wrappers.py:522: note:     def __setitem__(self, slice, Iterable[tuple[str, str]], /) -> None+ tests/test_wrappers.py:522: note:     def __setitem__(self, slice[int | Any, int | Any, int | Any], Iterable[tuple[str, str]], /) -> None- tests/test_wrappers.py:563: note:     def __setitem__(self, slice, Iterable[tuple[str, str]], /) -> None+ tests/test_wrappers.py:563: note:     def __setitem__(self, slice[int | Any, int | Any, int | Any], Iterable[tuple[str, str]], /) -> Noneibis (https://github.com/ibis-project/ibis)+ ibis/util.py:591: error: Unsupported operand types for + ("IntegerScalar" and "int")  [operator]+ ibis/util.py:591: note: Right operand is of type "int | Any"+ ibis/util.py:595: error: Unsupported operand types for + ("IntegerScalar" and "int")  [operator]+ ibis/util.py:595: note: Right operand is of type "int | Any"+ ibis/util.py:606: error: Unsupported operand types for - ("int" and "IntegerScalar")  [operator]+ ibis/util.py:606: note: Left operand is of type "int | Any"- ibis/util.py:607: error: Incompatible return value type (got "tuple[int | None, Any | int]", expected "tuple[int | IntegerScalar, int | IntegerScalar]")  [return-value]+ ibis/util.py:607: error: Incompatible return value type (got "tuple[int | None, int | Any]", expected "tuple[int | IntegerScalar, int | IntegerScalar]")  [return-value]- ibis/selectors.py:678: error: Incompatible types in assignment (expression has type "Slice", variable has type "str | int | slice | Iterable[int | str]")  [assignment]+ ibis/selectors.py:678: error: Incompatible types in assignment (expression has type "Slice", variable has type "str | int | slice[int | Any, int | Any, int | Any] | Iterable[int | str]")  [assignment]- ibis/selectors.py:679: error: Argument 1 to "ColumnIndex" has incompatible type "int | slice | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]"  [arg-type]+ ibis/selectors.py:679: error: Argument 1 to "ColumnIndex" has incompatible type "int | slice[int | Any, int | Any, int | Any] | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]"  [arg-type]+ ibis/expr/types/strings.py:110: error: Argument 2 to "StringSlice" has incompatible type "int | Any"; expected "Value[Integer, Any] | None"  [arg-type]+ ibis/expr/types/strings.py:110: error: Argument 3 to "StringSlice" has incompatible type "int | Any"; expected "Value[Integer, Any] | None"  [arg-type]- ibis/expr/types/arrays.py:147: error: Argument 2 to "ArraySlice" has incompatible type "Any | int"; expected "Value[Integer, Any]"  [arg-type]+ ibis/expr/types/arrays.py:147: error: Argument 2 to "ArraySlice" has incompatible type "int | Any"; expected "Value[Integer, Any]"  [arg-type]+ ibis/expr/types/arrays.py:147: error: Argument 3 to "ArraySlice" has incompatible type "int | Any"; expected "Value[Integer, Any] | None"  [arg-type]speedrun.com_global_scoreboard_webapp (https://github.com/Avasam/speedrun.com_global_scoreboard_webapp)- backend/api/tournament_scheduler_api.py:327: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:327: note:     def __getitem__(self, slice[int | Any, int | Any, int | Any], /) -> list[Any]- backend/api/tournament_scheduler_api.py:331: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:331: note:     def __getitem__(self, slice[int | Any, int | Any, int | Any], /) -> list[Any]- backend/api/tournament_scheduler_api.py:335: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:335: note:     def __getitem__(self, slice[int | Any, int | Any, int | Any], /) -> list[Any]streamlit (https://github.com/streamlit/streamlit)- lib/tests/streamlit/elements/lib/column_config_utils_test.py:385:13: note:     def __getitem__(self, Union[SupportsIndex, slice], /) -> str+ lib/tests/streamlit/elements/lib/column_config_utils_test.py:385:13: note:     def __getitem__(self, Union[SupportsIndex, slice[Union[int, Any], Union[int, Any], Union[int, Any]]], /) -> str- lib/tests/streamlit/runtime/state/query_params_test.py:264:37: note:         def __getitem__(self, slice, /) -> Tuple[Any, ...]+ lib/tests/streamlit/runtime/state/query_params_test.py:264:37: note:         def __getitem__(self, slice[Union[int, Any], Union[int, Any], Union[int, Any]], /) -> Tuple[Any, ...]discord.py (https://github.com/Rapptz/discord.py)- discord/http.py:233: note:     def __setitem__(self, slice, Iterable[Embed], /) -> None+ discord/http.py:233: note:     def __setitem__(self, slice[int | Any, int | Any, int | Any], Iterable[Embed], /) -> Noneoperator (https://github.com/canonical/operator)- ops/framework.py:1304: note:          def __getitem__(self, slice, /) -> MutableSequence[Any]+ ops/framework.py:1304: note:          def __getitem__(self, slice[int | Any, int | Any, int | Any], /) -> MutableSequence[Any]- ops/framework.py:1304: note:          def __getitem__(self, slice, /) -> Sequence[Any]+ ops/framework.py:1304: note:          def __getitem__(self, slice[int | Any, int | Any, int | Any], /) -> Sequence[Any]- ops/framework.py:1307: note:          def __setitem__(self, slice, Iterable[Any], /) -> None+ ops/framework.py:1307: note:          def __setitem__(self, slice[int | Any, int | Any, int | Any], Iterable[Any], /) -> None- ops/framework.py:1311: note:          def __delitem__(self, slice, /) -> None+ ops/framework.py:1311: note:          def __delitem__(self, slice[int | Any, int | Any, int | Any], /) -> Nonecolour (https://github.com/colour-science/colour)- colour/continuous/signal.py:843: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "slice"  [call-overload]+ colour/continuous/signal.py:843: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "slice[int | Any, int | Any, int | Any]"  [call-overload]- colour/continuous/signal.py:844: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "slice"  [call-overload]+ colour/continuous/signal.py:844: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "slice[int | Any, int | Any, int | Any]"  [call-overload]pandas-stubs (https://github.com/pandas-dev/pandas-stubs)+ tests/test_frame.py:224: error: Expression is of type "Any", not "DataFrame"  [assert-type]+ tests/test_frame.py:225: error: Expression is of type "Any", not "DataFrame"  [assert-type]+ tests/test_frame.py:2170: error: Expression is of type "tuple[Index[int], slice[Any, Any, Any]]", not "tuple[Index[int], slice[int | Any, int | Any, int | Any]]"  [assert-type]manticore (https://github.com/trailofbits/manticore)- tests/wasm/json2mc.py:103: note:     def __getitem__(self, slice, /) -> list[Any]+ tests/wasm/json2mc.py:103: note:     def __getitem__(self, slice[int | Any, int | Any, int | Any], /) -> list[Any]dd-trace-py (https://github.com/DataDog/dd-trace-py)- ddtrace/settings/config.py:888: note:     def __getitem__(self, SupportsIndex | slice, /) -> str+ ddtrace/settings/config.py:888: note:     def __getitem__(self, SupportsIndex | slice[int | Any, int | Any, int | Any], /) -> str

@github-actions
Copy link
Contributor

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

prefect (https://github.com/PrefectHQ/prefect)- src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice, /) -> tuple[Never, ...]+ src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice[Any, Any, Any], /) -> tuple[Never, ...]- src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice, /) -> Sequence[Never]+ src/prefect/utilities/annotations.py:41: note:          def __getitem__(self, slice[Any, Any, Any], /) -> Sequence[Never]- src/prefect/cli/cloud/__init__.py:326: note:     def __getitem__(self, SupportsIndex | slice, /) -> str+ src/prefect/cli/cloud/__init__.py:326: note:     def __getitem__(self, SupportsIndex | slice[Any, Any, Any], /) -> str- src/prefect/cli/deploy.py:1132: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1132: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1158: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1158: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1166: note:     def __setitem__(self, slice, Iterable[dict[Any, Any]], /) -> None+ src/prefect/cli/deploy.py:1166: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[dict[Any, Any]], /) -> None- src/prefect/cli/deploy.py:1183: note:     def __getitem__(self, slice, /) -> list[dict[Any, Any]]+ src/prefect/cli/deploy.py:1183: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[dict[Any, Any]]ibis (https://github.com/ibis-project/ibis)- ibis/selectors.py:678: error: Incompatible types in assignment (expression has type "Slice", variable has type "str | int | slice | Iterable[int | str]")  [assignment]+ ibis/selectors.py:678: error: Incompatible types in assignment (expression has type "Slice", variable has type "str | int | slice[Any, Any, Any] | Iterable[int | str]")  [assignment]- ibis/selectors.py:679: error: Argument 1 to "ColumnIndex" has incompatible type "int | slice | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]"  [arg-type]+ ibis/selectors.py:679: error: Argument 1 to "ColumnIndex" has incompatible type "int | slice[Any, Any, Any] | Iterable[int | str]"; expected "str | int | Slice | tuple[int | str, ...]"  [arg-type]werkzeug (https://github.com/pallets/werkzeug)- tests/test_wrappers.py:522: note:     def __setitem__(self, slice, Iterable[tuple[str, str]], /) -> None+ tests/test_wrappers.py:522: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[tuple[str, str]], /) -> None- tests/test_wrappers.py:563: note:     def __setitem__(self, slice, Iterable[tuple[str, str]], /) -> None+ tests/test_wrappers.py:563: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[tuple[str, str]], /) -> Nonestreamlit (https://github.com/streamlit/streamlit)- lib/tests/streamlit/elements/lib/column_config_utils_test.py:385:13: note:     def __getitem__(self, Union[SupportsIndex, slice], /) -> str+ lib/tests/streamlit/elements/lib/column_config_utils_test.py:385:13: note:     def __getitem__(self, Union[SupportsIndex, slice[Any, Any, Any]], /) -> str- lib/tests/streamlit/runtime/state/query_params_test.py:264:37: note:         def __getitem__(self, slice, /) -> Tuple[Any, ...]+ lib/tests/streamlit/runtime/state/query_params_test.py:264:37: note:         def __getitem__(self, slice[Any, Any, Any], /) -> Tuple[Any, ...]speedrun.com_global_scoreboard_webapp (https://github.com/Avasam/speedrun.com_global_scoreboard_webapp)- backend/api/tournament_scheduler_api.py:327: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:327: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]- backend/api/tournament_scheduler_api.py:331: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:331: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]- backend/api/tournament_scheduler_api.py:335: note:     def __getitem__(self, slice, /) -> list[Any]+ backend/api/tournament_scheduler_api.py:335: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]discord.py (https://github.com/Rapptz/discord.py)- discord/http.py:233: note:     def __setitem__(self, slice, Iterable[Embed], /) -> None+ discord/http.py:233: note:     def __setitem__(self, slice[Any, Any, Any], Iterable[Embed], /) -> Noneoperator (https://github.com/canonical/operator)- ops/framework.py:1304: note:          def __getitem__(self, slice, /) -> MutableSequence[Any]+ ops/framework.py:1304: note:          def __getitem__(self, slice[Any, Any, Any], /) -> MutableSequence[Any]- ops/framework.py:1304: note:          def __getitem__(self, slice, /) -> Sequence[Any]+ ops/framework.py:1304: note:          def __getitem__(self, slice[Any, Any, Any], /) -> Sequence[Any]- ops/framework.py:1307: note:          def __setitem__(self, slice, Iterable[Any], /) -> None+ ops/framework.py:1307: note:          def __setitem__(self, slice[Any, Any, Any], Iterable[Any], /) -> None- ops/framework.py:1311: note:          def __delitem__(self, slice, /) -> None+ ops/framework.py:1311: note:          def __delitem__(self, slice[Any, Any, Any], /) -> Nonecolour (https://github.com/colour-science/colour)- colour/continuous/signal.py:843: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "slice"  [call-overload]+ colour/continuous/signal.py:843: error: No overload variant of "__call__" of "_ComparisonOpLE" matches argument type "slice[Any, Any, Any]"  [call-overload]- colour/continuous/signal.py:844: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "slice"  [call-overload]+ colour/continuous/signal.py:844: error: No overload variant of "__call__" of "_ComparisonOpGE" matches argument type "slice[Any, Any, Any]"  [call-overload]pandas-stubs (https://github.com/pandas-dev/pandas-stubs)+ tests/test_frame.py:224: error: Expression is of type "Any", not "DataFrame"  [assert-type]+ tests/test_frame.py:225: error: Expression is of type "Any", not "DataFrame"  [assert-type]manticore (https://github.com/trailofbits/manticore)- tests/wasm/json2mc.py:103: note:     def __getitem__(self, slice, /) -> list[Any]+ tests/wasm/json2mc.py:103: note:     def __getitem__(self, slice[Any, Any, Any], /) -> list[Any]dd-trace-py (https://github.com/DataDog/dd-trace-py)- ddtrace/settings/config.py:888: note:     def __getitem__(self, SupportsIndex | slice, /) -> str+ ddtrace/settings/config.py:888: note:     def __getitem__(self, SupportsIndex | slice[Any, Any, Any], /) -> str

@AlexWaygood
Copy link
Member

Thepandas-stubs errors I discussed in#11637 (comment) are now theonly new false positives this PR introduces. I would say the cost-benefit is now in this PR's favour. (For one thing, we'd possibly find it quite useful for red-knot.)

@JukkaL, I'll see if I can narrow down the strangepandas-stubs primer hits to a mypy bug.

JukkaL reacted with thumbs up emoji

@AlexWaygoodAlexWaygood marked this pull request as ready for reviewOctober 24, 2024 13:17
Copy link
Collaborator

@srittausrittau left a comment

Choose a reason for hiding this comment

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

We can always refine this later, this is a good start!

@srittausrittau merged commit65405e9 intopython:mainOct 24, 2024
62 checks passed
@AlexWaygood
Copy link
Member

@JukkaL, I'll see if I can narrow down the strangepandas-stubs primer hits to a mypy bug.

@JukkaL I finally found some time to minimize this:python/mypy#18149

JukkaL reacted with heart emoji

hauntsaninja pushed a commit to python/mypy that referenced this pull requestNov 19, 2024
Fixes#18149Slices were made generic inpython/typeshed#11637. Currently, all sliceexpressions are inferred to have type `slice[Any, Any, Any]`. This PRfills in the generic type arguments more appropriately usingstart/stop/stride expression types.Given```pythonclass Foo:    def __getitem__[T](self, item: T) -> T: return itemx = Foo()reveal_type(x[1:])```Before:```nonemain.py:5: note: Revealed type is "builtins.slice[Any, Any, Any]"```After:```nonemain.py:5: note: Revealed type is "builtins.slice[builtins.int, None, None]"```
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@srittausrittausrittau approved these changes

@AlexWaygoodAlexWaygoodAlexWaygood approved these changes

+1 more reviewer

@randolf-scholzrandolf-scholzrandolf-scholz left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

builtins.slice should be generic

8 participants

@Sachaa-Thanasius@JelleZijlstra@cdce8p@srittau@hamdanal@AlexWaygood@JukkaL@randolf-scholz

[8]ページ先頭

©2009-2025 Movatter.jp