FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Cleaner error reporting for slice indexing by dibrinsofor · Pull Request #22134 · python/mypy · GitHub

Repository navigation

Cleaner error reporting for slice indexing - #22134

Open
dibrinsofor wants to merge 8 commits into
python:masterfrom
dibrinsofor:slice-reporting
Open

dibrinsofor wants to merge 8 commits into
python:masterfrom
dibrinsofor:slice-reporting

Conversation

Copy link
Copy Markdown

Fixes: #22117

Specialized error reporting for invalid slice bounds for __getitem__ and __setitem__.

Current:

a: list[int] = []
s: str

a[s:] # E: Invalid index type "slice[str, None, None]" for "list[int]"; expected type "slice[SupportsIndex | None, SupportsIndex | None, SupportsIndex | None]"  [index]

Proposed:

a: list[int] = []
s: str

a[s:] # E: Slice index must be an integer, SupportsIndex or None; got: "str"

It could be worthwhile to signal the position of the error a[b:c:d]

Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

hauntsaninja 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This isn't correct, since it will not respect the actual types on the call

hauntsaninja added the pending Issues that may be closed label Oct 21, 2026
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

Labels

pending Issues that may be closed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Have the type of the thing used in the slice for slice error

2 participants


Back | FazBrowse Home | New Git URL