You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow reify types to be mutable to avoid FrozenInstanceError from attrs (#1100)
Fixes#1088
I don't really like that I'm having to do this, but given that I think
such cases are likely fairly rare (and most likely confined to the
`io.IOBase` types) I think it's an acceptable compromise.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
7
7
## [Unreleased]
8
+
### Changed
9
+
* Types generated by `reify` may optionally be marked as `^:mutable` now to prevent `attrs.exceptions.FrozenInstanceError`s being thrown when mutating methods inherited from the supertype(s) are called (#1088)
Copy file name to clipboardExpand all lines: docs/concepts.rst
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1342,6 +1342,13 @@ Reified types always implement :py:class:`basilisp.lang.interfaces.IWithMeta` an
1342
1342
1343
1343
While ``reify`` and ``deftype`` are broadly similar, ``reify`` types may not define class or static methods.
1344
1344
1345
+
.. warning::
1346
+
1347
+
If a reified type is defined with a mutable "abstract" supertype (such as :external:py:class:`io.IOBase`), users may experience errors arising from the ``attrs``-generated ``__setattr__`` method for the underlying type when mutating methods are called on the resulting object.
1348
+
Reified types are immutable (or "frozen" in ``attrs`` lingo) by default.
1349
+
When a mutating method, such as :external:py:meth:`io.IOBase.close`, is called on the type (which may be called manually or it may be called at VM shutdown), the mutation will fail due to ``attrs`` replacing the ``__setattr__`` method on the type.
1350
+
It is possible to force Basilisp to generate a mutable (non-frozen) type for reified types by applying the ``^:mutable`` metadata on the ``reify`` symbol.
0 commit comments