@@ -155,28 +155,14 @@ def safe_getitem(obj, index):
155
155
raise ValueError ('unsafe to lookup on object of type %s' % (type (obj ), ))
156
156
157
157
158
- # This function is under the Python License, Version 2
159
- # This license requires modifications to the code be reported.
160
- # Based on ast.NodeVisitor.generic_visit
161
- # Modifications:
162
- # * Now a standalone function instead of method
163
- # * now hardcoded to look for Attribute node with given attr name
164
- # * returns values back up the recursive call stack to stop once target found
165
158
def find_attribute_with_name (node , name ):
166
- """Search depth-first for getitem indexing with name"""
167
159
if isinstance (node , ast .Attribute ) and node .attr == name :
168
160
return node
169
- for _ , value in ast .iter_fields (node ):
170
- if isinstance (value , list ):
171
- for item in value :
172
- if isinstance (item , ast .AST ):
173
- r = find_attribute_with_name (item , name )
174
- if r :
175
- return r
176
- elif isinstance (value , ast .AST ):
177
- r = find_attribute_with_name (value , name )
178
- if r :
179
- return r
161
+ for item in ast .iter_child_nodes (node ):
162
+ r = find_attribute_with_name (item , name )
163
+ if r :
164
+ return r
165
+
180
166
181
167
def evaluate_current_expression (cursor_offset , line , namespace = None ):
182
168
"""
0 commit comments