Skip to content

♻️ refactor: hoist config override machinery into LocalConfigurable - #798

Merged
nstarman merged 1 commit into
GalacticDynamics:mainfrom
nstarman:claude/config-dedup-twins
Jul 25, 2026
Merged

♻️ refactor: hoist config override machinery into LocalConfigurable#798
nstarman merged 1 commit into
GalacticDynamics:mainfrom
nstarman:claude/config-dedup-twins

Conversation

@nstarman

Copy link
Copy Markdown
Contributor

Summary

The QuantityReprConfig and QuantityStrConfig classes in unxt._src.config were near-identical twins: each carried its own copy of __getattribute__ (the thread-local override lookup) and override() (the context-manager builder). The two copies differed only in:

  • the key-set constant they referenced (QUANTITY_REPR_CONFIG_KEYS vs QUANTITY_STR_CONFIG_KEYS — identical 4-name frozensets),
  • the class name interpolated into error messages, and
  • the short_arrays default.

This PR moves both methods into the shared LocalConfigurable base, keyed off a per-subclass _config_keys allowlist. 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 that LocalConfigurable provides them, that intermediate base is redundant and is removed — ParametricQuantityReprConfig / ParametricQuantityStrConfig inherit directly from LocalConfigurable. Their now-unused imports (contextlib, Config, _NestedConfigContext) are dropped.

Behavior

Unchanged. The override() cfg-branch still intersects the Config-specified names with each class's override allowlist (specified & keys); _local remains per-instance (set in LocalConfigurable.__init__), so repr/str override stacks stay independent.

Verification

  • ruff check / ruff format clean; all pre-commit hooks pass
  • 181 tests pass: tests/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

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>
Copilot AI review requested due to automatic review settings July 25, 2026 02:19
@github-actions github-actions Bot added 🧩 unxts-parametric Issues/PRs affecting the unxts.parametric namespace package ♻️ Refactor code Refactor code. labels Jul 25, 2026
@nstarman nstarman added this to the v2.0.x milestone Jul 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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__) and override() context-manager construction into LocalConfigurable, using a per-subclass _config_keys allowlist.
  • Update QuantityReprConfig / QuantityStrConfig to declare _config_keys and rely on the shared base implementation.
  • Remove unxts.parametric’s _ParametricLocalConfig and unused imports, switching parametric config classes to inherit directly from LocalConfigurable.

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

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.15385% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.59%. Comparing base (c9d3955) to head (ffdef0c).

Files with missing lines Patch % Lines
src/unxt/_src/config.py 96.15% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@nstarman
nstarman merged commit 98b8ce5 into GalacticDynamics:main Jul 25, 2026
39 checks passed
@nstarman
nstarman deleted the claude/config-dedup-twins branch July 25, 2026 14:35
nstarman added a commit that referenced this pull request Jul 25, 2026
…ocalConfigurable (#800)

Co-authored-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

♻️ Refactor code Refactor code. 🧩 unxts-parametric Issues/PRs affecting the unxts.parametric namespace package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants