Skip to content

Reject array slice assignment before mutating values - #600

Merged
frostming merged 1 commit into
python-poetry:masterfrom
Gonghan-Princess:codex/fix-array-slice-assignment-state
Sep 11, 2026
Merged

Reject array slice assignment before mutating values#600
frostming merged 1 commit into
python-poetry:masterfrom
Gonghan-Princess:codex/fix-array-slice-assignment-state

Conversation

@Gonghan-Princess

Copy link
Copy Markdown
Contributor

Summary

Array.__setitem__ rejects slice assignment only after modifying the underlying list. For example, assigning [9, 10] to a[1:2] on [1, 2, 3] raises ValueError, but leaves the in-memory value as [1, 9, 10, 3] while serialization still produces [1, 2, 3].

Check for unsupported slices before converting or assigning the replacement. The six regression cases cover replacement, insertion, deletion through assignment, and extended/reversed slices. They assert that values and the original commented TOML remain unchanged after the exception, and that subsequent supported edits still round-trip.

Validation on Windows with Python 3.12.10: all 1,058 tests pass, including the TOML conformance suite. All six new cases fail on the unmodified implementation. All configured pre-commit hooks pass on the tracked repository files. Full mypy reports the same 29 diagnostics on both this branch and the unmodified upstream commit (five in project code and 24 in the test submodule).

Related: #599 addresses slice deletion in __delitem__; this change concerns rejected slice assignment in __setitem__.

Agent Drafting Metadata

  • Agent: OpenAI Codex
  • Model: GPT-6
  • Notes: AI-assisted investigation, implementation, regression tests, and PR drafting. The reproduction and reported checks were executed locally.

@frostming
frostming merged commit 4b38bec into python-poetry:master Sep 11, 2026
25 checks passed
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