Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow SupportsIndex in slice expressions #14738

Merged
merged 1 commit into from
Mar 11, 2023

Conversation

hauntsaninja
Copy link
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
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]

Copy link
Collaborator

@JukkaL JukkaL left a comment

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
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants