Closed
Labels
Milestone
Description
See dataclasses, new in Python 3.7. (This pretty much fills the same role as MacroPy's case classes.)
We could raise dataclasses.FrozenInstanceError where appropriate.
Also, e.g. unpythonic.llist.cons doesn't need the internal readonly flag; it's simpler to just call object.__setattr__ to init the read-only fields, so the custom __setattr__ can be simplified. (Should check also other datatypes that use this pattern, maybe something in unpythonic.collections?)
Also, must intercept also __delattr__ to properly emulate immutability. Not sure if we currently do this (probably not - hence the bug label, we need to check).
Activity
Technologicat commentedon Apr 24, 2026
Investigation (2026-04-24):
Confirmed the
__delattr__gap is real. Demonstration:Current implementation at
unpythonic/llist.py:218-225intercepts only__setattr__. A subsequentdel c.carslips throughobject.__delattr__.Survey of the rest of the codebase:
unpythonic/env.pyalready intercepts both__setattr__and__delattr__(env is mutable but with controlled mutation) — good model.unpythonic/assignonce.pyintercepts only__setattr__and is by design allowed to set once; never rebinding meansdelis also semantically wrong there. Should likely also intercept__delattr__.unpythonic/collections.py:388is theshimproxy, not an immutable — not in scope.frozendictis adictsubclass;__setitem__/__delitem__are the right hooks (already handled).Plan for 2.2.0:
cons: intercept__delattr__symmetrically; useobject.__setattr__at init time to drop the_immutablesentinel dance; raisedataclasses.FrozenInstanceErrorinstead of bareTypeErrorfor stdlib parity.assignonce: intercept__delattr__(raiseAttributeErrorwith an explanatory message, since "set once" implies "no unset").delon both.— Claude (Opus 4.7)
llist: cons __delattr__ + simplify via object.__setattr__
assignonce: forbid del on defined names
env: drop _direct_write whitelist
collections: clarify frozendict freezes mapping not attributes
CHANGELOG, briefs: 2.2.0 #35 done
llist: FrozenAttributeError shim, raised by cons
Technologicat commentedon May 6, 2026
Closed for 2.2.0. Five commits on master:
ee66ff7llist: cons __delattr__ + simplify via object.__setattr__— bug fix (was missing) plus simplification (drop_immutablesentinel, init viaobject.__setattr__).95c05fbassignonce: forbid del on defined names— closes thedel e.foo; e.foo = new_valuebypass that was inherited fromenv.6c79667env: drop _direct_write whitelist— sameobject.__setattr__cleanup pattern; closes the gap where client code could clobber_env/_finalized.dae7c30collections: clarify frozendict freezes mapping not attributes— docstring note (intentional, not a bug).2798d86llist: FrozenAttributeError shim, raised by cons— multiply-inherits fromTypeError(legacy) anddataclasses.FrozenInstanceError(stdlib convention since 3.7). Eitherexceptclause catches.The
TypeErrorbase of the shim is scheduled for removal in 3.0.0; tracked in #102.Tests: 3767/3767 pass locally; CI matrix green.
— Claude (Opus 4.7)
CHANGELOG, briefs: 2.2.0 #82 done
Release 2.2.0 "Hail Eris"