♻️ refactor: hoist config override machinery into LocalConfigurable - #798
Conversation
The `QuantityReprConfig` / `QuantityStrConfig` twins each carried an
identical `__getattribute__` (thread-local override lookup) and
`override()` context manager, differing only by their key-set constant,
the class name in error messages, and the `short_arrays` default. Move
both methods into the shared `LocalConfigurable` base, keyed off a
per-subclass `_config_keys` allowlist, so each concrete config declares
only its traits and default.
The same two methods were copied a third and fourth time into
`unxts.parametric`'s `_ParametricLocalConfig`; that intermediate base is
now redundant and removed — `ParametricQuantity{Repr,Str}Config` inherit
directly from `LocalConfigurable`.
Behavior is unchanged (181 config/parametric/printing tests + doctests
pass). Net -167 lines.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors the thread-local override machinery for nested config objects by hoisting the duplicated __getattribute__ override lookup and override() context manager builder into the shared LocalConfigurable base in unxt._src.config, keyed by a per-subclass _config_keys allowlist. It also removes the now-redundant _ParametricLocalConfig base in unxts.parametric, having the parametric repr/str config classes inherit directly from LocalConfigurable.
Changes:
- Move thread-local override lookup (
__getattribute__) andoverride()context-manager construction intoLocalConfigurable, using a per-subclass_config_keysallowlist. - Update
QuantityReprConfig/QuantityStrConfigto declare_config_keysand rely on the shared base implementation. - Remove
unxts.parametric’s_ParametricLocalConfigand unused imports, switching parametric config classes to inherit directly fromLocalConfigurable.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/unxt/_src/config.py | Centralizes thread-local override behavior in LocalConfigurable and updates quantity repr/str configs to use _config_keys. |
| packages/unxts.parametric/src/unxts/parametric/_src/config.py | Removes redundant local-config base and simplifies parametric config classes to inherit LocalConfigurable directly. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #798 +/- ##
==========================================
+ Coverage 91.98% 96.59% +4.61%
==========================================
Files 83 44 -39
Lines 3766 2496 -1270
Branches 313 142 -171
==========================================
- Hits 3464 2411 -1053
+ Misses 227 54 -173
+ Partials 75 31 -44 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ocalConfigurable (#800) Co-authored-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
Summary
The
QuantityReprConfigandQuantityStrConfigclasses inunxt._src.configwere near-identical twins: each carried its own copy of__getattribute__(the thread-local override lookup) andoverride()(the context-manager builder). The two copies differed only in:QUANTITY_REPR_CONFIG_KEYSvsQUANTITY_STR_CONFIG_KEYS— identical 4-name frozensets),short_arraysdefault.This PR moves both methods into the shared
LocalConfigurablebase, keyed off a per-subclass_config_keysallowlist. Each concrete config now declares only its traits, docstring, and_config_keys.The same two methods had been copied a third and fourth time into
unxts.parametric's_ParametricLocalConfig. Now thatLocalConfigurableprovides them, that intermediate base is redundant and is removed —ParametricQuantityReprConfig/ParametricQuantityStrConfiginherit directly fromLocalConfigurable. Their now-unused imports (contextlib,Config,_NestedConfigContext) are dropped.Behavior
Unchanged. The
override()cfg-branch still intersects theConfig-specified names with each class's override allowlist (specified & keys);_localremains per-instance (set inLocalConfigurable.__init__), so repr/str override stacks stay independent.Verification
ruff check/ruff formatclean; all pre-commit hooks passtests/unit/test_config.py,tests/unit/test_quantity_printing.py,packages/unxts.parametric/tests, plus the config-module doctests (unxt + parametric)Net
−167 lines (136 insertions, 303 deletions) across the two files.
🤖 Generated with Claude Code