Skip to content

Make ImageArray a descriptor to enforce ImageFile.image type invariant#33

Merged
gb119 merged 3 commits intostablefrom
copilot/modify-imagearray-as-descriptor
Mar 20, 2026
Merged

Make ImageArray a descriptor to enforce ImageFile.image type invariant#33
gb119 merged 3 commits intostablefrom
copilot/modify-imagearray-as-descriptor

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

ImageFile.image was a plain @property with no type enforcement at the class level. This mirrors the DataArray descriptor pattern (PR #32) to ImageArray/ImageFile.

Changes

  • ImageArray — descriptor protocol: Added __set_name__, __get__, __set__ so any ImageArray instance can serve as a data descriptor. The setter preserves filename/metadata from the previous image and handles the in-place stack-update path.

  • ImageFile — replace @property with class-level descriptor:

    # Before
    @property
    def image(self): return self._image
    @image.setter
    def image(self, v): ...  # 12 lines of conversion logic
    
    # After
    image = ImageArray()
    """ImageArray descriptor that enforces the image attribute is always an ImageArray instance."""
  • KerrImageFile — fix subclass override: @ImageFile.image.getter / @ImageFile.image.setter are property-only patterns that broke once image became a descriptor. Replaced with a self-contained @property / @image.setter pair that overrides the descriptor in the subclass.

  • Tests: Added test_image_descriptor covering class-level type assertion, numpy→ImageArray coercion, metadata preservation, and filename preservation across image replacement.


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

Copilot AI changed the title [WIP] Update ImageArray to be a descriptor for ImageFile Make ImageArray a descriptor to enforce ImageFile.image type invariant Mar 20, 2026
Copilot AI requested a review from gb119 March 20, 2026 21:33
@gb119 gb119 changed the base branch from main to stable March 20, 2026 21:37
@gb119 gb119 marked this pull request as ready for review March 20, 2026 21:48
@gb119 gb119 merged commit 197268f into stable Mar 20, 2026
6 of 11 checks passed
@gb119 gb119 deleted the copilot/modify-imagearray-as-descriptor branch March 20, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants