Repository navigation
Fix Grid property layer instance attribute collisions - #3954
Merged
quaquel merged 1 commit intoOct 22, 2026
Merged
Conversation
|
Performance benchmarks:
|
quaquel
approved these changes
Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevent property layers from overwriting existing Grid instance attributes, such as
dimensionsandtorus.Also remove the corresponding Grid attribute when deleting a property layer, allowing its name to be reused under the new collision check.
Bug / Issue
Related background:
Issue #3839 was resolved by PR #3840, which added protection against overwriting attributes defined on Cell classes, such as
is_empty,is_full, andposition.This PR addresses a separate collision involving attributes stored on the Grid instance itself:
width,heightis_empty,is_full,positiondimensions,torus,_cellsGrid._attach_property_layer()checked the Grid class hierarchy and Cell attributes, but omittedself.__dict__. Consequently,setattr(self, name, array)could replace existing Grid state with a NumPy array.The following reproduction was confirmed on the pre-fix
mainbaseline at2b2c9251, which already includes the merged PR #3840:Creating the layer succeeds, but the subsequent query raises a NumPy ambiguous-truth-value
ValueErrorbecausegrid.dimensionshas been replaced by the layer array.A layer named
torussimilarly replaces the boolean configuration with an array, causing theif self.toruscheck to fail. Bothcreate_property_layer()andadd_property_layer()are affected.Expected behavior: reject a conflicting name with a clear
ValueErrorbefore modifying the layer registry, Grid attributes, or Cell accessors, leaving the grid usable.Implementation
already existserror.remove_property_layer(). This prevents a stale attribute from blocking recreation of a previously removed layer.emptylayer initialization.Testing
Added 16 parameterized regression cases covering:
Local validation on macOS with Python 3.14.5:
git diff --checkpassed.Additional Notes
Issue #3839 is already closed and PR #3840 is already merged. They are referenced as background for the Cell-level protection that remains in place. This PR adds protection for the distinct Grid-instance collision demonstrated above.