Skip to content

Commit 28482ce

Browse files
committed
Renamed '_update_nested_values' to '_recursive_update', and updated comments
1 parent e187d9b commit 28482ce

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/murfey/util/config.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,24 +161,26 @@ def machine_config_from_file(
161161
dictionary, before finally updating the keys for that specific instrument.
162162
"""
163163

164-
def _update_nested_values(base: dict[str, Any], new: dict[str, Any]):
164+
def _recursive_update(base: dict[str, Any], new: dict[str, Any]):
165165
"""
166-
Helper function to recursively update nested dictionary values.
166+
Helper function to recursively update nested dictionaries.
167+
167168
If the old and new values are both dicts, it will add the new keys and values
168169
to the existing dictionary recursively without overwriting entries.
170+
169171
If the old and new values are both lists, it will extend the existing list.
170172
For all other values, it will overwrite the existing value with the new one.
171173
"""
172174
for key, value in new.items():
173175
# If new values are dicts and dict values already exist, do recursive update
174176
if key in base and isinstance(base[key], dict) and isinstance(value, dict):
175-
base[key] = _update_nested_values(base[key], value)
177+
base[key] = _recursive_update(base[key], value)
176178
# If new values are lists and a list already exists, extend the list
177179
elif (
178180
key in base and isinstance(base[key], list) and isinstance(value, list)
179181
):
180182
base[key].extend(value)
181-
# Otherwise, overwrite values as normal
183+
# Otherwise, overwrite/add values as normal
182184
else:
183185
base[key] = value
184186
return base
@@ -202,17 +204,17 @@ def _update_nested_values(base: dict[str, Any], new: dict[str, Any]):
202204

203205
# Populate with general values
204206
general_config: dict[str, Any] = master_config.get("general", {})
205-
config = _update_nested_values(config, general_config)
207+
config = _recursive_update(config, general_config)
206208

207209
# Populate with shared instrument values
208210
instrument_config: dict[str, Any] = master_config.get(i, {})
209211
instrument_shared_config: dict[str, Any] = master_config.get(
210212
str(instrument_config.get("instrument_type", "")).lower(), {}
211213
)
212-
config = _update_nested_values(config, instrument_shared_config)
214+
config = _recursive_update(config, instrument_shared_config)
213215

214216
# Insert instrument-specific values
215-
config = _update_nested_values(config, instrument_config)
217+
config = _recursive_update(config, instrument_config)
216218

217219
# Add to master dictionary
218220
all_machine_configs[i] = MachineConfig(**config)

0 commit comments

Comments
 (0)