Skip to content

Fix reverse slice mutations in ObservableList - #3962

Merged
quaquel merged 1 commit into
mesa:mainfrom
ska2704:fix-observable-list-reverse-slices
Oct 22, 2026
Merged

quaquel merged 1 commit into
mesa:mainfrom
ska2704:fix-observable-list-reverse-slices

Conversation

@ska2704

@ska2704 ska2704 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Pre-PR Checklist

  • This PR is a bug fix, not a new feature or enhancement.

Summary

Make negative-step slice assignment and deletion on ObservableList follow Python list semantics. For example, items[::-1] = [4, 5, 6] on a three-element list currently raises, while del items[::-1] silently leaves the list unchanged.

Bug / Issue

Fixes #3961.

Implementation

Use the original slice to read and mutate the underlying list. Keep normalized bounds for the signal's index field. Reconstructing a slice from slice.indices() reinterprets its -1 stop sentinel as an index relative to the end, which turns full reverse slices into empty slices.

Testing

  • Full suite: pytest --durations=10 tests/ -Werror -Wdefault::PendingDeprecationWarning, 896 passed on Python 3.12.11 and macOS, including browser tests.
  • Signals and batching suites: 60 passed.
  • All applicable pre-commit hooks passed for both changed files.

The 17 added cases produced 11 failures and 6 passes against unchanged main. They cover reverse and strided replacement/deletion, clipped and empty slices, replacement iterators, invalid replacement lengths, and batched notifications. The unchanged full suite passed all 879 tests.

Additional Notes

Signal index normalization remains unchanged.

All six CI test-matrix jobs pass (Linux Python 3.12, 3.13, 3.14, prerelease dependencies; Windows and macOS Python 3.14), along with coverage and pre-commit. The separate mesa-examples job fails on an outdated mesa.meta_agents import, matching the failure on unchanged main.

@github-actions github-actions Bot added experimental Release notes label testing Release notes label labels Oct 22, 2026
@ska2704

ska2704 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

The examples failure also occurs on unchanged main (d0124f8). Both jobs stop during collection at examples/warehouse/warehouse/model.py:9 with ModuleNotFoundError: No module named 'mesa.meta_agents':

The branch is current with main. All six test-matrix jobs, coverage, and pre-commit pass. The import failure is in the separate mesa-examples checkout, outside this change.

@github-actions

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -3.4% [-4.1%, -2.7%] 🔵 +0.2% [-0.0%, +0.4%]
BoltzmannWealth large 🔵 -2.6% [-2.9%, -2.2%] 🟢 -8.6% [-9.5%, -7.8%]
Schelling small 🔵 -0.2% [-0.9%, +0.5%] 🔵 -0.6% [-1.3%, +0.2%]
Schelling large 🔵 +1.5% [+0.6%, +2.5%] 🔴 +6.6% [+4.8%, +8.2%]
WolfSheep small 🔵 +0.4% [+0.0%, +0.9%] 🔵 +1.8% [-2.9%, +6.3%]
WolfSheep large 🔵 +1.4% [+0.0%, +2.8%] 🔵 +2.2% [-0.4%, +4.6%]
SugarscapeG1mt small 🔵 -1.3% [-1.9%, -0.7%] 🔵 -0.5% [-2.3%, +1.1%]
SugarscapeG1mt large 🔵 -3.1% [-4.3%, -1.8%] 🔵 -2.2% [-5.1%, +0.4%]
BoidFlockers small 🔵 -1.8% [-2.1%, -1.4%] 🔵 +0.2% [-0.2%, +0.7%]
BoidFlockers large 🔵 -1.0% [-1.4%, -0.6%] 🔵 -0.2% [-0.5%, +0.1%]
MultiLevelAllianceModel small 🔵 -4.1% [-5.2%, -3.0%] 🔵 +0.0% [-0.5%, +0.8%]
MultiLevelAllianceModel large 🔵 -1.4% [-2.2%, -0.5%] 🔵 -0.3% [-1.5%, +0.6%]

@quaquel quaquel added the bug Release notes label label Oct 22, 2026
@quaquel
quaquel merged commit 093e967 into mesa:main Oct 22, 2026
16 of 17 checks passed
EwoutH pushed a commit that referenced this pull request Oct 28, 2026
@ska2704
ska2704 deleted the fix-observable-list-reverse-slices branch November 5, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Release notes label experimental Release notes label testing Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ObservableList reverse slice mutations raise or leave values unchanged

2 participants