Repository navigation
Conversation
Wkhanex
left a comment
There was a problem hiding this comment.
AI-assisted validation at 349167ab83c5 on Python 3.12.14: I compared assignment, deletion, and insertion with single-use __index__ objects at six positions (-100, -3, -1, 0, 2, 100) against native lists. Error behavior and serialized data matched in all 18 cases, including unchanged data after out-of-range assignment/deletion. Four additional forward/reverse slices also converted each supplied bound exactly once. The 50 array-focused tests passed.
The far-out-of-range cases are a useful guard for the order of normalization and mutation: rejection must leave both the list data and formatted storage untouched. I checked rendered state independently with tomllib, rather than relying only on array equality.
Summary
Array assignment, deletion, and insertion accept objects implementing
__index__through their underlying list operations, but subsequently compare or look up the original object when updating the formatted array. For example, assigning with an index object returning0changes[1, 2]into[3, 2]and then raisesTypeError, leavingas_string()as[1, 2].Normalize scalar indices before mutation and reuse the resulting integer for the formatted storage. Normalize slice components once, in the same step/start/stop order as a list, so deleting with stateful index objects does not convert them again after changing the list. Update the affected annotations to accept
SupportsIndex.Validation: 17 new regression cases fail on the unchanged source; all 25 focused cases pass after the fix. The full suite passes on Python 3.9 (1,226 passed, one skipped) and 3.11 (1,227 passed), and all configured pre-commit hooks pass. Mypy reports the same eight existing repository errors on the original and patched trees, excluding the external toml-test submodule.
Agent Drafting Metadata