1
0
forked from VimPlug/jedi

Cleanup with_stmt.

This commit is contained in:
Dave Halter
2017-04-09 21:20:33 +02:00
parent f855c2bb70
commit 769cc80d6b
2 changed files with 6 additions and 7 deletions

View File

@@ -192,7 +192,7 @@ def _name_to_types(evaluator, context, tree_name):
elif typ == 'expr_stmt':
types = _remove_statements(evaluator, context, node, tree_name)
elif typ == 'with_stmt':
types = context.eval_node(node.node_from_name(tree_name))
types = context.eval_node(node.get_context_manager_from_name(tree_name))
elif typ in ('import_from', 'import_name'):
types = imports.infer_import(context, tree_name)
elif typ in ('funcdef', 'classdef'):

View File

@@ -789,11 +789,10 @@ class WithStmt(Flow):
names += _defined_names(with_item.children[2])
return names
def node_from_name(self, name):
node = name
while True:
node = node.parent
if node.type == 'with_item':
def get_context_manager_from_name(self, name):
node = name.parent
if node.type != 'with_item':
raise ValueError('The name is not actually part of a with statement.')
return node.children[0]