Skip to content

Clean up and harden Dimensions.py#51

Merged
pnorton-usgs merged 3 commits into
developmentfrom
refactor/dimensions-cleanup
May 11, 2026
Merged

Clean up and harden Dimensions.py#51
pnorton-usgs merged 3 commits into
developmentfrom
refactor/dimensions-cleanup

Conversation

@pnorton-usgs
Copy link
Copy Markdown
Member

Clean up and harden Dimensions.py

Summary

Removes dead code, protects internal state from external mutation, and improves the ParamDimensions API.

Changes

Dead code removal

  • Remove obsolete commented-out initialization logic in Dimensions.__init__
  • Remove commented-out XML attribute alternatives in both xml properties

Encapsulation

  • dimensions property now returns a MappingProxyType (read-only view) instead of the raw internal dict
  • Prevents external code from bypassing add()/remove() by directly mutating the dict
  • All read operations (keys, values, items, [], in, iteration) continue to work unchanged

ParamDimensions improvements

  • Add MAX_DIMS = 2 class constant to make the dimension limit explicit and configurable
  • Add index() method (more Pythonic name for getting a dimension's position)
  • Keep get_position() as a deprecated alias for backward compatibility
  • Fix get_dimsize_by_index docstring: documented :raises ValueError: but actually raises IndexError

Testing

All 290 tests pass.

- Remove obsolete commented-out initialization logic in Dimensions.__init__
- Remove commented-out XML attribute alternatives in Dimensions.xml
- Remove commented-out XML attribute alternatives in ParamDimensions.xml
- Return a read-only MappingProxyType view from the dimensions property
  instead of the raw internal dict
- Prevents external code from bypassing add()/remove() validation by
  directly mutating the dict (e.g. pop, del, clear, direct assignment)
- All read operations (keys, values, items, [], in, iteration) continue
  to work unchanged
- Add MAX_DIMS class constant to make the 2-dimension limit explicit
- Rename get_position() to index() (more Pythonic); keep get_position()
  as a deprecated alias for backward compatibility
- Fix get_dimsize_by_index docstring: was ':raises ValueError:' but
  actually raises IndexError
@pnorton-usgs pnorton-usgs self-assigned this May 11, 2026
@pnorton-usgs pnorton-usgs merged commit 763ba35 into development May 11, 2026
7 checks passed
@pnorton-usgs pnorton-usgs deleted the refactor/dimensions-cleanup branch May 11, 2026 15:54
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.

1 participant