Refactor: Type safety improvement, public mask API update, and the experimental layer creation API updates #516
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
This PR makes the distinction between regular masks and "real" (combined pixel + vector) masks explicit in the public API, improving type safety and usability.
Key Improvements
has_real()API: Changed from private_has_real()to publichas_real(), allowing users to explicitly check if a mask has combined pixel+vector dataMaskProtocolwith complete interface definition, eliminating circular importsorfallback in mask coordinate properties to handle edge cases where real mask fields are None_psd._mark_updated()pattern throughout GroupMixin operationsChanges by Module
Mask API (
src/psd_tools/api/mask.py)_has_real()from private to publichas_real()self._data.real_left or self._data.leftAnytoLayerProtocoldataproperty to access raw MaskDataProtocol Enhancements (
src/psd_tools/api/protocols.py)MaskProtocolwithhas_real(),width,height,datapropertiesLayerProtocolandPSDProtocoltype coverageLayer Tree Management (
src/psd_tools/api/layers.py)Layer.__init__()to takeparentparameter, deriving_psdfrom parent_psd._mark_updated()calls_update_children()+_psd._mark_updated()patternCall Sites
has_real(), added explicit None checkshas_real()Validation Improvements
_assert_data()helperDocumentation
Testing
Benefits
layer.mask.has_real()to check for combined masksBreaking Changes
None - this is a backwards-compatible refactoring. Existing code continues to work as before.
🤖 Generated with Claude Code