docs: document and pin BaseConfig.from_dict / from_object semantics#93
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Summary
Documents the intentional asymmetry between
BaseConfig.from_dictandBaseConfig.from_object(DES-3 from an internal audit):from_dictincludes any key present in the dict; unknown keys are silently dropped; explicitNoneoverrides defaults.from_objectincludes only attributes whose value is notNone(Noneor missing falls back to dataclass defaults); falsy non-Nonevalues 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 matchingfrom_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_attributetest_from_object_skips_missing_attributetest_from_object_preserves_falsy_valuestest_from_dict_drops_unknown_keys_silentlytest_from_dict_explicit_none_overrides_defaultThese 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.from_objectbody 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