Skip to content

Clean up and modernize parameters directory#53

Merged
pnorton-usgs merged 7 commits into
developmentfrom
refactor/parameters-cleanup
May 11, 2026
Merged

Clean up and modernize parameters directory#53
pnorton-usgs merged 7 commits into
developmentfrom
refactor/parameters-cleanup

Conversation

@pnorton-usgs
Copy link
Copy Markdown
Member

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

  • Delete ParameterSet.py — entire file was commented-out dead code (96 lines)
  • Remove commented-out reshape method from Parameter.py (~45 lines)
  • Remove commented-out size property, old namedtuple comments, debug prints
  • Remove commented-out code from Parameters.py and ParameterFile.py

Modernize type hints

  • 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
  • Fix verbose parameter types: Optional[bool]bool (None was never meaningful)

Replace __getattr__ in Parameters

  • Remove __getattr__ delegation to internal __parameters dict
  • Add __contains__, __iter__, __len__ for Pythonic collection behavior
  • Update exists() to use __contains__
  • Improves IDE support, prevents accidental dict mutation

Fix fragile private method access

  • Rename MetaData.__parameters_to_dict to MetaData._parameters_to_dict (single underscore)
  • Update ParamDb.py to use the clean internal method name instead of name-mangled _MetaData__parameters_to_dict

Parameter.py minor improvements

  • 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

Encapsulation

  • parameters 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

Testing

All 290 tests pass.

- 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
@pnorton-usgs pnorton-usgs self-assigned this May 11, 2026
@pnorton-usgs pnorton-usgs merged commit a35c6f6 into development May 11, 2026
7 checks passed
@pnorton-usgs pnorton-usgs deleted the refactor/parameters-cleanup branch May 11, 2026 18:23
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