forked from VimPlug/jedi
Finally able to remove the get_executable_nodes function.
This commit is contained in:
@@ -208,92 +208,3 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None):
|
||||
obj = obj.parent
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_executable_nodes(module):
|
||||
"""
|
||||
Returns the nodes used in a module. All these nodes should be
|
||||
evaluated to check for potential exceptions.
|
||||
"""
|
||||
def check_children(node):
|
||||
try:
|
||||
children = node.children
|
||||
except AttributeError:
|
||||
return []
|
||||
else:
|
||||
nodes = []
|
||||
for child in children:
|
||||
nodes += check_children(child)
|
||||
if child.type == 'trailer':
|
||||
c = child.children
|
||||
if c[0] == '(' and c[1] != ')':
|
||||
if c[1].type != 'arglist':
|
||||
if c[1].type == 'argument':
|
||||
nodes.append(c[1].children[-1])
|
||||
else:
|
||||
nodes.append(c[1])
|
||||
else:
|
||||
for argument in c[1].children:
|
||||
if argument.type == 'argument':
|
||||
nodes.append(argument.children[-1])
|
||||
elif argument.type != 'operator':
|
||||
nodes.append(argument)
|
||||
return nodes
|
||||
|
||||
def add_nodes(nodes):
|
||||
new = set()
|
||||
for node in nodes:
|
||||
if isinstance(node, tree.Flow):
|
||||
children = node.children
|
||||
if node.type == 'for_stmt':
|
||||
children = children[2:] # Don't want to include the names.
|
||||
# Pick the suite/simple_stmt.
|
||||
new |= add_nodes(children)
|
||||
elif node.type in ('simple_stmt', 'suite'):
|
||||
new |= add_nodes(node.children)
|
||||
elif node.type in ('return_stmt', 'yield_expr', 'raise_stmt'):
|
||||
try:
|
||||
new.add(node.children[1])
|
||||
except IndexError:
|
||||
pass
|
||||
elif node.type not in ('whitespace', 'operator', 'keyword',
|
||||
'parameters', 'decorated', 'except_clause') \
|
||||
and not isinstance(node, (tree.ClassOrFunc, tree.Import)):
|
||||
new.add(node)
|
||||
try:
|
||||
children = node.children
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
for next_node in children:
|
||||
new.update(check_children(node))
|
||||
return new
|
||||
|
||||
nodes = set()
|
||||
import_names = set()
|
||||
decorated_funcs = []
|
||||
for scope in module.walk():
|
||||
for imp in set(scope.imports):
|
||||
import_names |= set(imp.get_defined_names())
|
||||
if imp.is_nested():
|
||||
import_names |= set(path[-1] for path in imp.paths())
|
||||
|
||||
children = scope.children
|
||||
if isinstance(scope, tree.ClassOrFunc):
|
||||
children = children[2:] # We don't want to include the class name.
|
||||
nodes |= add_nodes(children)
|
||||
|
||||
for flow in scope.flows:
|
||||
if flow.type == 'for_stmt':
|
||||
nodes.add(flow.children[3])
|
||||
elif flow.type == 'try_stmt':
|
||||
nodes.update(e for e in flow.except_clauses() if e is not None)
|
||||
|
||||
try:
|
||||
decorators = scope.get_decorators()
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
if decorators:
|
||||
decorated_funcs.append(scope)
|
||||
return nodes, import_names, decorated_funcs
|
||||
|
||||
Reference in New Issue
Block a user