Skip to content

GH-16791: Make Sequence.__getitem__(slice) return Self - #16792

Open
loic-simon wants to merge 1 commit into
python:mainfrom
loic-simon:GH-16791-sequence-getitem-slice-return-self
Open

loic-simon wants to merge 1 commit into
python:mainfrom
loic-simon:GH-16791-sequence-getitem-slice-return-self

Conversation

@loic-simon

Copy link
Copy Markdown
Contributor

Exploratory PR for #16791

@github-actions

Copy link
Copy Markdown
Contributor

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

aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/web_routedef.py:151:6: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ aiohttp/web_routedef.py:151:6: note:      Superclass:
+ aiohttp/web_routedef.py:151:6: note:          @overload
+ aiohttp/web_routedef.py:151:6: note:          def __getitem__(self, int, /) -> AbstractRouteDef
+ aiohttp/web_routedef.py:151:6: note:          @overload
+ aiohttp/web_routedef.py:151:6: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> RouteTableDef
+ aiohttp/web_routedef.py:151:6: note:      Subclass:
+ aiohttp/web_routedef.py:151:6: note:          @overload
+ aiohttp/web_routedef.py:151:6: note:          def __getitem__(self, int, /) -> AbstractRouteDef
+ aiohttp/web_routedef.py:151:6: note:          @overload
+ aiohttp/web_routedef.py:151:6: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> list[AbstractRouteDef]

operator (https://github.com/canonical/operator)
- ops/framework.py:1383: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> Sequence[Any]
+ ops/framework.py:1383: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> StoredList

kopf (https://github.com/nolar/kopf)
+ kopf/_cogs/structs/diffs.py:89: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ kopf/_cogs/structs/diffs.py:89: note:      Superclass:
+ kopf/_cogs/structs/diffs.py:89: note:          @overload
+ kopf/_cogs/structs/diffs.py:89: note:          def __getitem__(self, int, /) -> DiffItem
+ kopf/_cogs/structs/diffs.py:89: note:          @overload
+ kopf/_cogs/structs/diffs.py:89: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> Diff
+ kopf/_cogs/structs/diffs.py:89: note:      Subclass:
+ kopf/_cogs/structs/diffs.py:89: note:          @overload
+ kopf/_cogs/structs/diffs.py:89: note:          def __getitem__(self, int, /) -> DiffItem
+ kopf/_cogs/structs/diffs.py:89: note:          @overload
+ kopf/_cogs/structs/diffs.py:89: note:          def __getitem__(self, slice[Any, Any, Any], /) -> Sequence[DiffItem]

django-stubs (https://github.com/typeddjango/django-stubs)
+ django-stubs/core/paginator.pyi:76: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ django-stubs/core/paginator.pyi:76: note:      Superclass:
+ django-stubs/core/paginator.pyi:76: note:          @overload
+ django-stubs/core/paginator.pyi:76: note:          def __getitem__(self, int, /) -> _T
+ django-stubs/core/paginator.pyi:76: note:          @overload
+ django-stubs/core/paginator.pyi:76: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> Page[_T]
+ django-stubs/core/paginator.pyi:76: note:      Subclass:
+ django-stubs/core/paginator.pyi:76: note:          @overload
+ django-stubs/core/paginator.pyi:76: note:          def __getitem__(self, int, /) -> _T
+ django-stubs/core/paginator.pyi:76: note:          @overload
+ django-stubs/core/paginator.pyi:76: note:          def __getitem__(self, slice[Any, Any, Any], /) -> Sequence[_T]

discord.py (https://github.com/Rapptz/discord.py)
+ discord/utils.py:253: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ discord/utils.py:253: note:      Superclass:
+ discord/utils.py:253: note:          @overload
+ discord/utils.py:253: note:          def __getitem__(self, int, /) -> T_co
+ discord/utils.py:253: note:          @overload
+ discord/utils.py:253: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> SequenceProxy[T_co]
+ discord/utils.py:253: note:      Subclass:
+ discord/utils.py:253: note:          @overload
+ discord/utils.py:253: note:          def __getitem__(self, SupportsIndex, /) -> T_co
+ discord/utils.py:253: note:          @overload
+ discord/utils.py:253: note:          def __getitem__(self, slice[Any, Any, Any], /) -> list[T_co]

schemathesis (https://github.com/schemathesis/schemathesis)
+ src/schemathesis/grpc/loaders.py:19: note: ... from here:

cwltool (https://github.com/common-workflow-language/cwltool)
+ tests/test_provenance.py:14: note: In module imported here:
+ mypy-stubs/rdflib/namespace/__init__.pyi: note: In member "__getitem__" of class "Namespace":
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:      Superclass:
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:          @overload
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:          def __getitem__(self, int, /) -> str
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:          @overload
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> Namespace
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:      Subclass:
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:          def __getitem__(self, Any, /) -> URIRef
+ mypy-stubs/rdflib/graph.pyi:6: note: In module imported here,
+ .../projects/_cwltool_venv/lib/python3.13/site-packages/schema_salad/utils.py:9: note: ... from here,
+ cwltool/cwlprov/writablebagfile.py:18: note: ... from here:
+ mypy-stubs/rdflib/query.pyi: note: In member "__getitem__" of class "ResultRow":
+ mypy-stubs/rdflib/query.pyi:12:6: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ mypy-stubs/rdflib/query.pyi:12:6: note:      Superclass:
+ mypy-stubs/rdflib/query.pyi:12:6: note:          @overload
+ mypy-stubs/rdflib/query.pyi:12:6: note:          def __getitem__(self, int, /) -> Identifier
+ mypy-stubs/rdflib/query.pyi:12:6: note:          @overload
+ mypy-stubs/rdflib/query.pyi:12:6: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> ResultRow
+ mypy-stubs/rdflib/query.pyi:12:6: note:      Subclass:
+ mypy-stubs/rdflib/query.pyi:12:6: note:          @overload
+ mypy-stubs/rdflib/query.pyi:12:6: note:          def __getitem__(self, str, /) -> Identifier
+ mypy-stubs/rdflib/query.pyi:12:6: note:          @overload
+ mypy-stubs/rdflib/query.pyi:12:6: note:          def __getitem__(self, SupportsIndex, /) -> Identifier
+ mypy-stubs/rdflib/query.pyi:12:6: note:          @overload
+ mypy-stubs/rdflib/query.pyi:12:6: note:          def __getitem__(self, slice[Any, Any, Any], /) -> tuple[Identifier, ...]

schema_salad (https://github.com/common-workflow-language/schema_salad)
+ mypy-stubs/rdflib/graph.pyi:6: note: In module imported here,
+ src/schema_salad/tests/test_misc.py:1: note: ... from here:
+ mypy-stubs/rdflib/query.pyi: note: In member "__getitem__" of class "ResultRow":
+ mypy-stubs/rdflib/query.pyi:12:6: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ mypy-stubs/rdflib/query.pyi:12:6: note:      Superclass:
+ mypy-stubs/rdflib/query.pyi:12:6: note:          @overload
+ mypy-stubs/rdflib/query.pyi:12:6: note:          def __getitem__(self, int, /) -> Identifier
+ mypy-stubs/rdflib/query.pyi:12:6: note:          @overload
+ mypy-stubs/rdflib/query.pyi:12:6: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> ResultRow
+ mypy-stubs/rdflib/query.pyi:12:6: note:      Subclass:
+ mypy-stubs/rdflib/query.pyi:12:6: note:          @overload
+ mypy-stubs/rdflib/query.pyi:12:6: note:          def __getitem__(self, str, /) -> Identifier
+ mypy-stubs/rdflib/query.pyi:12:6: note:          @overload
+ mypy-stubs/rdflib/query.pyi:12:6: note:          def __getitem__(self, SupportsIndex, /) -> Identifier
+ mypy-stubs/rdflib/query.pyi:12:6: note:          @overload
+ mypy-stubs/rdflib/query.pyi:12:6: note:          def __getitem__(self, slice[Any, Any, Any], /) -> tuple[Identifier, ...]
+ src/schema_salad/jsonld_context.py:8: note: In module imported here:
+ mypy-stubs/rdflib/namespace/__init__.pyi: note: In member "__getitem__" of class "Namespace":
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:      Superclass:
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:          @overload
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:          def __getitem__(self, int, /) -> str
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:          @overload
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> Namespace
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:      Subclass:
+ mypy-stubs/rdflib/namespace/__init__.pyi:38:5: note:          def __getitem__(self, Any, /) -> URIRef

pytest-autoprofile (https://gitlab.com/TTsangSC/pytest-autoprofile)
+ src/pytest_autoprofile/_multiprocessing.py:398: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ src/pytest_autoprofile/_multiprocessing.py:398: note:      Superclass:
+ src/pytest_autoprofile/_multiprocessing.py:398: note:          @overload
+ src/pytest_autoprofile/_multiprocessing.py:398: note:          def __getitem__(self, int, /) -> Any
+ src/pytest_autoprofile/_multiprocessing.py:398: note:          @overload
+ src/pytest_autoprofile/_multiprocessing.py:398: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> _TaskResult
+ src/pytest_autoprofile/_multiprocessing.py:398: note:      Subclass:
+ src/pytest_autoprofile/_multiprocessing.py:398: note:          @overload
+ src/pytest_autoprofile/_multiprocessing.py:398: note:          def __getitem__(self, int, /) -> int | tuple[Literal[True], Any] | tuple[Literal[False], Exception]
+ src/pytest_autoprofile/_multiprocessing.py:398: note:          @overload
+ src/pytest_autoprofile/_multiprocessing.py:398: note:          def __getitem__(self, slice[Any, Any, Any], /) -> tuple[int | tuple[Literal[True], Any] | tuple[Literal[False], Exception], ...]

more-itertools (https://github.com/more-itertools/more-itertools)
+ more_itertools/more.pyi:628: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ more_itertools/more.pyi:628: note:      Superclass:
+ more_itertools/more.pyi:628: note:          @overload
+ more_itertools/more.pyi:628: note:          def __getitem__(self, int, /) -> _T_co
+ more_itertools/more.pyi:628: note:          @overload
+ more_itertools/more.pyi:628: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> SequenceView[_T_co]
+ more_itertools/more.pyi:628: note:      Subclass:
+ more_itertools/more.pyi:628: note:          @overload
+ more_itertools/more.pyi:628: note:          def __getitem__(self, int, /) -> _T_co
+ more_itertools/more.pyi:628: note:          @overload
+ more_itertools/more.pyi:628: note:          def __getitem__(self, slice[Any, Any, Any], /) -> Sequence[_T_co]

meson (https://github.com/mesonbuild/meson)
+ mesonbuild/arglist.py:157:6: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ mesonbuild/arglist.py:157:6: note:      Superclass:
+ mesonbuild/arglist.py:157:6: note:          @overload
+ mesonbuild/arglist.py:157:6: note:          def __getitem__(self, int, /) -> str
+ mesonbuild/arglist.py:157:6: note:          @overload
+ mesonbuild/arglist.py:157:6: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> CompilerArgs
+ mesonbuild/arglist.py:157:6: note:      Subclass:
+ mesonbuild/arglist.py:157:6: note:          @overload
+ mesonbuild/arglist.py:157:6: note:          def __getitem__(self, int, /) -> str
+ mesonbuild/arglist.py:157:6: note:          @overload
+ mesonbuild/arglist.py:157:6: note:          def __getitem__(self, slice[Any, Any, Any], /) -> MutableSequence[str]

werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/datastructures/accept.py:52: error: Signature of "__getitem__" incompatible with supertype "typing.Sequence"  [override]
+ src/werkzeug/datastructures/accept.py:52: note:      Superclass:
+ src/werkzeug/datastructures/accept.py:52: note:          @overload
+ src/werkzeug/datastructures/accept.py:52: note:          def __getitem__(self, int, /) -> tuple[str, float]
+ src/werkzeug/datastructures/accept.py:52: note:          @overload
+ src/werkzeug/datastructures/accept.py:52: note:          def __getitem__(self, slice[int | None, int | None, int | None], /) -> Accept
+ src/werkzeug/datastructures/accept.py:52: note:      Subclass:
+ src/werkzeug/datastructures/accept.py:52: note:          @overload
+ src/werkzeug/datastructures/accept.py:52: note:          def __getitem__(self, str, /) -> float
+ src/werkzeug/datastructures/accept.py:52: note:          @overload
+ src/werkzeug/datastructures/accept.py:52: note:          def __getitem__(self, SupportsIndex, /) -> tuple[str, float]
+ src/werkzeug/datastructures/accept.py:52: note:          @overload
+ src/werkzeug/datastructures/accept.py:52: note:          def __getitem__(self, slice[Any, Any, Any], /) -> tuple[tuple[str, float]]

@srittau

This comment was marked as outdated.

This branch has not been deployed

No deployments
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.

2 participants