Skip to content

Allow SupportsIndex in slice expressions - #14738

Merged
hauntsaninja merged 1 commit into
python:masterfrom
hauntsaninja:slice-supports-index
Mar 11, 2023
Merged

hauntsaninja merged 1 commit into
python:masterfrom
hauntsaninja:slice-supports-index

Conversation

@hauntsaninja

Copy link
Copy Markdown
Collaborator

Helps with #2410, as suggested by BvB93 in #2410 (comment)

PEP 696 will be the real solution here, since it will allow us to make slice generic with few backward compatibility issues

Helps with python#2410, as suggested by BvB93 in python#2410 (comment)

PEP 696 will be the real solution here, since it will allow us to make
slice generic
@github-actions

Copy link
Copy Markdown
Contributor

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

pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/arrays/masked.py:963: error: Unused "type: ignore" comment

ibis (https://github.com/ibis-project/ibis)
- ibis/expr/datatypes/tests/test_core.py:309: error: Slice index must be an integer or None  [misc]
+ ibis/expr/datatypes/tests/test_core.py:309: error: Slice index must be an integer, SupportsIndex or None  [misc]

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a reasonable short-term improvement while we are waiting for PEP 696.

[file typing_extensions.pyi]
from typing import Protocol
class SupportsIndex(Protocol):
def __index__(self) -> int: ...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Optionally, also add a pythoneval test case so that we'll verify that typing_extensions is still imported in builtins/typing. Eventually all extensions might be in typing and we'll need to switch to typing.SupportsIndex.

@hauntsaninja
hauntsaninja merged commit fb6b8bc into python:master Mar 11, 2023
@hauntsaninja
hauntsaninja deleted the slice-supports-index branch March 11, 2023 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants