@@ -155,28 +155,14 @@ def safe_getitem(obj, index):
155155 raise ValueError ('unsafe to lookup on object of type %s' % (type (obj ), ))
156156
157157
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
165158def find_attribute_with_name (node , name ):
166- """Search depth-first for getitem indexing with name"""
167159 if isinstance (node , ast .Attribute ) and node .attr == name :
168160 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+
180166
181167def evaluate_current_expression (cursor_offset , line , namespace = None ):
182168 """
0 commit comments