GeezerVison is showing github.com — Switch frozen-instance error type from TypeError to dataclasses.FrozenInstanceError · Issue #102 · Technologicat/unpythonic
Switch frozen-instance error type from TypeError to dataclasses.FrozenInstanceError #102
Description
Spun off from #35 (closed in 2.2.0): the immutability cleanup for unpythonic.llist.cons (and any future "frozen" types in this codebase) shipped raising TypeError to preserve API stability under the 2.x compatibility promise.
Standard library convention since Python 3.7 is dataclasses.FrozenInstanceError for "tried to mutate a frozen instance." Aligning is desirable for ecosystem consistency, but FrozenInstanceError subclasses AttributeError, not TypeError. Switching is therefore a breaking change for any user code catching TypeError from a cons mutation attempt — appropriate for a major-version bump.
Scope
unpythonic/llist.py: cons.__setattr__ and cons.__delattr__ raise dataclasses.FrozenInstanceError instead of TypeError.
- Tests: update
unpythonic/tests/test_llist.py immutability assertions to expect FrozenInstanceError (or AttributeError).
- CHANGELOG: Changed (breaking) entry under 3.0.0.
- Audit any other "frozen" types added between now and 3.0.0 for the same alignment.
Notes
assignonce.__delattr__ (added in 2.2.0) raises AttributeError, which already aligns naturally — leave alone.
frozendict does not currently lock down attribute writes (only mapping writes); this issue is about types whose contract is "frozen instance."
— Claude (Opus 4.7)
Activity
Technologicat commented on May 6, 2026
Update: shim approach landed in 2.2.0. unpythonic.llist.FrozenAttributeError multiply-inherits from TypeError and dataclasses.FrozenInstanceError; cons raises this. Either except TypeError or except FrozenInstanceError catches.
Scope of this issue therefore shifts:
- 3.0.0 work is now to drop the
TypeError base from FrozenAttributeError (or replace usages with plain FrozenInstanceError and remove the shim class).
- The compat-during-2.x problem is solved; this is a clean stdlib-alignment step for 3.0.0.
— Claude (Opus 4.7)
Metadata
Metadata
Development
No branches or pull requestsIssue actions