Repository navigation
Preserve read_only property layers across Grid pickling and deepcopy - #3731
Conversation
|
Performance benchmarks:
|
|
The fix seems fine. However, I am wondering whether it would not be a good idea to store on the space which layers are read only and which ones are not. |
|
Thanks @AshNicolus for the PR and bug report. I agree with @quaquel that making the state explicit feels cleaner than inferring it via |
|
Good call, done. Switched to an explicit |
|
hey @AshNicolus 1 minor Q: do we need any additional safeguards in setstate if _read_only_layers contains a layer name that is no longer present in property_layers, or is that state impossible given the current lifecycle of property layers? |
|
@dietcoke-17 Good question. No extra safeguard is needed, for two reasons:
I confirmed this: adding a bogus name to |
Closes #3730
What
Read-only property layers on a
Gridbecame writable again after the grid waspickled (or deepcopied).
Grid.__setstate__rebuilt every property layer with botha getter and a setter, ignoring the original
read_onlyflag, so the restrictionthat
_attach_property_layerset up was silently lost on the round trip.Reproduction
Fix
The read-only status is now carried through the pickle round trip:
__getstate__records the set of read-only layers (those whose cell-classaccessor has
fset is None).__setstate__rebuilds each accessor as getter-only when the layer was read-only,and getter+setter otherwise, mirroring
_attach_property_layer.The change is confined to the two pickle methods.
copy.deepcopyuses the samemethods, so it is fixed too.
Test
Added
test_read_only_property_layer_survives_pickle_and_deepcopy: after bothdeepcopyandpickleround trips, a read-only layer still raisesAttributeErroron write, while a read-write layer remains writable.
Full
tests/discrete_space/suite passes under-Werror; ruff clean.