Allow SupportsIndex in slice expressions#14738
Merged
hauntsaninja merged 1 commit intopython:masterfrom Mar 11, 2023
Merged
Conversation
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
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
approved these changes
Feb 21, 2023
Collaborator
JukkaL
left a comment
There was a problem hiding this comment.
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: ... |
Collaborator
There was a problem hiding this comment.
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.
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.
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