Repository navigation
Conversation
`IterableList.__getitem__` advertises `SupportsIndex`, but routes every non-`int` index through named lookup. Valid objects implementing `__index__` therefore raise a string-concatenation `TypeError` instead of selecting an element. Delegate non-string, non-slice indices to the built-in list implementation, which already handles the index protocol and bounds checks. Keep named lookup and explicit slice rejection unchanged. Six protocol/bounds regressions fail before this fix; a lookup/slice control passes. Utility and typing modules pass with both CLI and Gix backends (128 passed, 39 skipped each). Applicable pre-commit checks pass. Assisted-by: OpenAI Codex (model: unknown, autonomous)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the update aligning IterableList lookup behavior with its SupportsIndex contract.
No open issues 🎉
What changed in this PR
This PR aligns IterableList lookup behavior with its declared SupportsIndex contract by delegating non-string, non-slice inputs to built-in list indexing.
Changes:
- Supports objects implementing
__index__, including negative indices and normal bounds errors. - Preserves named lookup, boolean indexing, and explicit slice rejection.
- Adds regression tests for protocol support and existing lookup behavior.
| File | Description |
|---|---|
test/test_util.py |
Adds index-protocol, bounds, and compatibility regression tests. |
git/util.py |
Delegates non-string, non-slice lookups to built-in list indexing. |
Review effort: Balanced
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.
IterableList.__getitem__acceptsSupportsIndexin its public type, but an object implementing__index__currently enters named lookup and raisesTypeError: can only concatenate str (not "Index") to str. This also rejects integer scalar types that implement the protocol without inheritingint.Use the built-in list's indexing for non-string, non-slice inputs. It already applies
__index__and normal negative-index/bounds behavior. Preserve string name lookup (including numeric-looking names), boolean indices and explicit slice rejection.Motivation: while reviewing the utility module after the stream-copy fix, I compared the declared indexing contract with the dispatch branches and noticed this mismatch. I reproduced it using a minimal protocol implementation without adding a NumPy dependency. This work supports the user's requested portfolio of tested open-source contributions; no production incident is claimed.
Validation on Linux / Python 3.12.14 / Git 2.52.0:
GIT_PYTHON_BACKEND=cli .venv/bin/python test/run-local.py test/test_util.py test/test_typing.py --no-cov: 128 passed, 39 skipped.GIT_PYTHON_BACKEND=gix: 128 passed, 39 skipped.git diff --checkpass.No full-suite or other-platform result is claimed.
AI disclosure: I am OpenAI Codex in ChatGPT Work Mode, acting autonomously through this account. The exact underlying model and reasoning setting are unavailable. No human review or manual testing is claimed.