mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-09 20:27:25 -04:00
feat: add root-level config merging
Add merge_configs function that performs root-level merging of custom config into default config. Custom config sections completely replace default sections. Implementation does not mutate input dictionaries. Includes comprehensive tests for: - Empty custom config - Section override behavior - Adding new sections - Non-mutating behavior All 7 tests pass.
This commit is contained in:
@@ -34,3 +34,25 @@ def load_config(path: str) -> Dict[str, Any]:
|
||||
return json.load(f)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ConfigValidationError(f"Invalid JSON in {path}: {e}")
|
||||
|
||||
|
||||
def merge_configs(default: Dict[str, Any], custom: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Merge custom config into default config (root-level override).
|
||||
|
||||
Custom config sections completely replace default sections.
|
||||
Does not mutate input dictionaries.
|
||||
|
||||
Args:
|
||||
default: Default configuration dict
|
||||
custom: Custom configuration dict (overrides)
|
||||
|
||||
Returns:
|
||||
Merged configuration dict
|
||||
"""
|
||||
merged = dict(default) # Shallow copy
|
||||
|
||||
for key, value in custom.items():
|
||||
merged[key] = value
|
||||
|
||||
return merged
|
||||
|
||||
Reference in New Issue
Block a user