Skip to content

Commit 1d5ade0

Browse files
committed
Refactored field evaluation.
1 parent 5ec2dc5 commit 1d5ade0

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

jmespath/visitor.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,23 @@ def visit_subexpression(self, node, value):
131131
return result
132132

133133
def visit_field(self, node, value, *args, **kwargs):
134-
135134
identifier = node['value']
136-
137-
## inner function to retrieve the given
138-
## value from the scopes stack
139-
140-
def get_value_from_current_context_or_scopes():
141-
if 'scopes' in kwargs:
142-
return kwargs['scopes'].getValue(identifier)
143-
return None
144-
145-
## search for identifier value
135+
scopes = kwargs.get('scopes')
146136

147137
try:
148138
result = value.get(identifier)
149139
if result == None:
150-
result = get_value_from_current_context_or_scopes()
140+
result = self._get_from_scopes(
141+
identifier, *args, scopes=scopes)
151142
return result
152143
except AttributeError:
153-
return get_value_from_current_context_or_scopes()
144+
return self._get_from_scopes(
145+
identifier, *args, scopes=scopes)
154146

147+
def _get_from_scopes(self, identifier, *args, **kwargs):
148+
if 'scopes' in kwargs:
149+
return kwargs['scopes'].getValue(identifier)
150+
return None
155151

156152
def visit_comparator(self, node, value):
157153
# Common case: comparator is == or !=

0 commit comments

Comments
 (0)