Skip to content

docs: document and pin BaseConfig.from_dict / from_object semantics#93

Merged
lesnik512 merged 1 commit into
mainfrom
fix/des-3-config-method-semantics
May 31, 2026
Merged

docs: document and pin BaseConfig.from_dict / from_object semantics#93
lesnik512 merged 1 commit into
mainfrom
fix/des-3-config-method-semantics

Conversation

@lesnik512

@lesnik512 lesnik512 commented May 31, 2026

Copy link
Copy Markdown
Member

Summary

Documents the intentional asymmetry between BaseConfig.from_dict and BaseConfig.from_object (DES-3 from an internal audit):

  • from_dict includes any key present in the dict; unknown keys are silently dropped; explicit None overrides defaults.
  • from_object includes only attributes whose value is not None (None or missing falls back to dataclass defaults); falsy non-None values are preserved.

One-line docstrings added to each method. from_object's body is also condensed from a 5-line imperative form to a single dict-comprehension matching from_dict's style — functionally identical and locked in by the new pinning tests.

Five pinning tests added (closing TEST-5 and TEST-6 from the audit):

  • test_from_object_skips_none_attribute
  • test_from_object_skips_missing_attribute
  • test_from_object_preserves_falsy_values
  • test_from_dict_drops_unknown_keys_silently
  • test_from_dict_explicit_none_overrides_default

These pass before and after the docstring additions — they pin existing behavior to prevent future regressions where someone "unifies" the two methods without realizing the asymmetry is intentional.

Closes DES-3, TEST-5, TEST-6 from an internal audit.

Test plan

  • just test -- tests/test_config.py -v — seven tests pass.
  • just test — full suite 89/89.
  • just lint — clean.
  • Reviewer: confirm the from_object body condensation (5 lines → 1 dict-comprehension with walrus) is functionally identical. If you'd rather see the docstring change land without the body cleanup, request a revert — the pinning tests verify both forms.

🤖 Generated with Claude Code

The two builder classmethods on BaseConfig have intentionally asymmetric
semantics that aren't obvious from reading the code:

- from_dict includes any key present in the dict (explicit None overrides
  the default); unknown keys are silently dropped.
- from_object includes only attributes whose value is not None; attributes
  set to None or missing entirely fall back to the dataclass default.
  Falsy non-None values (False, "", []) are preserved.

Add one-line docstrings capturing each method's contract. Condense the
from_object body to a single dict-comprehension matching from_dict's style;
behavior is identical (verified by the new pinning tests).

Add four pinning tests on top of the two pre-existing tests:
- test_from_object_skips_none_attribute
- test_from_object_skips_missing_attribute
- test_from_object_preserves_falsy_values
- test_from_dict_drops_unknown_keys_silently

Closes DES-3, TEST-5, TEST-6 from the audit.
@codecov

codecov Bot commented May 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
lite_bootstrap/instruments/base.py 100.00% <100.00%> (ø)
tests/test_config.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lesnik512 lesnik512 self-assigned this May 31, 2026
@lesnik512 lesnik512 merged commit d2f622b into main May 31, 2026
8 checks passed
@lesnik512 lesnik512 deleted the fix/des-3-config-method-semantics branch May 31, 2026 21:34
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