Clean up and modernize parameters directory#53
Merged
Conversation
- Add 'from __future__ import annotations' to all parameter files - Replace typing.Dict, List, Set, Optional, Union with built-in generics and X | Y syntax - Simplify super() calls to Python 3 style - Remove commented-out Rich console setup code - Fix verbose parameter types: Optional[bool] -> bool (None was never a meaningful value)
- Remove __getattr__ delegation to internal __parameters dict - Add __contains__ for 'name in params' syntax - Add __iter__ for 'for name in params:' iteration - Add __len__ for len(params) - Update exists() to use __contains__ - Improves IDE support, prevents accidental dict mutation, and produces clear error messages on typos
- Change from double-underscore (name-mangled private) to single-underscore (internal but accessible) since ParamDb already accesses it externally - Eliminates fragile name-mangled access pattern (mobj._MetaData__parameters_to_dict) in ParamDb.py - Method is now accessed as mobj._parameters_to_dict
- Parameter.py: remove commented-out reshape method (~45 lines), size property, old namedtuple comments - Parameters.py: remove commented-out debug prints, old return statements, and alternative implementations - ParameterFile.py: remove commented-out verify parameter, old attribute initializations, and debug print
- Add __repr__ method for debugging - Add -> bool return type annotation to is_scalar property - Replace isinstance(indices, type(dict().values())) with isinstance(indices, ValuesView) from collections.abc
- Return a read-only MappingProxyType view from the parameters property 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
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 modernize parameters directory
Summary
Removes dead code, modernizes type hints, replaces implicit
__getattr__delegation, fixes a fragile private method access pattern, and improves encapsulation across the parameters directory.Changes
Dead code removal
ParameterSet.py— entire file was commented-out dead code (96 lines)reshapemethod fromParameter.py(~45 lines)sizeproperty, old namedtuple comments, debug printsParameters.pyandParameterFile.pyModernize type hints
from __future__ import annotationsto all parameter filestyping.Dict,List,Set,Optional,Unionwith built-in generics andX | Ysyntaxsuper()calls to Python 3 styleverboseparameter types:Optional[bool]→bool(None was never meaningful)Replace
__getattr__in Parameters__getattr__delegation to internal__parametersdict__contains__,__iter__,__len__for Pythonic collection behaviorexists()to use__contains__Fix fragile private method access
MetaData.__parameters_to_dicttoMetaData._parameters_to_dict(single underscore)ParamDb.pyto use the clean internal method name instead of name-mangled_MetaData__parameters_to_dictParameter.py minor improvements
__repr__method for debugging-> boolreturn type annotation tois_scalarpropertyisinstance(indices, type(dict().values()))withisinstance(indices, ValuesView)fromcollections.abcEncapsulation
parametersproperty now returns aMappingProxyType(read-only view) instead of the raw internal dictadd()/remove()by directly mutating the dictTesting
All 290 tests pass.