Skip to content

Switch frozen-instance error type from TypeError to dataclasses.FrozenInstanceError #102

@Technologicat

Description

@Technologicat

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions