Skip to content

Commit e56a9b0

Browse files
MaxGhenisclaude
andcommitted
Refactor get_parameter to extract _find_child function
- Added a dedicated _find_child function to encapsulate child lookup logic - Simplified _navigate_to_node by delegating child lookup to _find_child - Improves separation of concerns and testability - Achieves 100% test coverage Addresses code review feedback from @mikesmit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 4874ece commit e56a9b0

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

policyengine_core/parameters/operations/get_parameter.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,35 @@ def _navigate_to_node(node, path_component, full_path):
3939
failed_at=path_component,
4040
)
4141

42-
# Look up the name in the node's children
42+
# Find the child node by name
43+
child_node = _find_child(node, name_part, full_path)
44+
45+
# If we have a bracket index, access the brackets property
46+
if index is not None:
47+
return _access_bracket(
48+
child_node, name_part, index, path_component, full_path
49+
)
50+
51+
return child_node
52+
53+
54+
def _find_child(node, name_part, full_path):
55+
"""
56+
Find a child node by name, providing helpful error messages when not found.
57+
58+
Args:
59+
node: The parent node to search in
60+
name_part: The name of the child to find
61+
full_path: The full parameter path being accessed (for error reporting)
62+
63+
Returns:
64+
The found child node
65+
66+
Raises:
67+
ParameterPathError: When the child cannot be found, with helpful suggestions
68+
"""
4369
try:
44-
child_node = node.children[name_part]
70+
return node.children[name_part]
4571
except KeyError:
4672
suggestions = _find_similar_parameters(node, name_part)
4773
suggestion_text = (
@@ -53,14 +79,6 @@ def _navigate_to_node(node, path_component, full_path):
5379
failed_at=name_part,
5480
)
5581

56-
# If we have a bracket index, access the brackets property
57-
if index is not None:
58-
return _access_bracket(
59-
child_node, name_part, index, path_component, full_path
60-
)
61-
62-
return child_node
63-
6482

6583
def _handle_bracket_access(node, path_component, full_path):
6684
"""Handle bracket access on an existing ParameterScale object."""

0 commit comments

Comments
 (0)