Clean up and harden Dimensions.py#51
Merged
Merged
Conversation
- 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
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.
Clean up and harden Dimensions.py
Summary
Removes dead code, protects internal state from external mutation, and improves the
ParamDimensionsAPI.Changes
Dead code removal
Dimensions.__init__xmlpropertiesEncapsulation
dimensionsproperty now returns aMappingProxyType(read-only view) instead of the raw internal dictadd()/remove()by directly mutating the dictkeys,values,items,[],in, iteration) continue to work unchangedParamDimensions improvements
MAX_DIMS = 2class constant to make the dimension limit explicit and configurableindex()method (more Pythonic name for getting a dimension's position)get_position()as a deprecated alias for backward compatibilityget_dimsize_by_indexdocstring: documented:raises ValueError:but actually raisesIndexErrorTesting
All 290 tests pass.