Skip to content

fix: freeze immutable collection backing state - #302

Merged
dbrattli merged 1 commit into
mainfrom
fix/freeze-immutable-collections
Nov 12, 2026
Merged

dbrattli merged 1 commit into
mainfrom
fix/freeze-immutable-collections

Conversation

@dbrattli

Copy link
Copy Markdown
Owner

Block and Map currently allow callers to replace their backing state, and mutating a shared map tree node can change multiple maps. Freeze the collection wrappers and tree nodes, and use slots (including an empty slot declaration on PipeMixin) to remove writable instance dictionaries.

Existing fluent and functional APIs retain shallow immutability: updates produce new collections while contained objects retain their own mutability. Ordinary assignment and deletion of backing fields now raise FrozenInstanceError; code relying on instance dictionaries or dynamic attributes must stop doing so. Copying, pickle round trips, weak references, pattern matching, and existing equality/hash behavior are preserved.

Adds regression coverage for mutation attempts and shared nodes, plus documentation examples explaining the guarantee and deliberate bypasses.

Verification: just check (lint, strict typing, and full test suite).

@dbrattli
dbrattli merged commit 6552eb0 into main Nov 12, 2026
6 checks passed
@dbrattli
dbrattli deleted the fix/freeze-immutable-collections branch November 12, 2026 00:32
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.

1 participant