forked from VimPlug/jedi
Get with statements working.
This commit is contained in:
@@ -299,6 +299,8 @@ class NameFinder(object):
|
|||||||
types += self._eval_param(typ)
|
types += self._eval_param(typ)
|
||||||
elif typ.isinstance(pr.ExprStmt):
|
elif typ.isinstance(pr.ExprStmt):
|
||||||
types += self._remove_statements(typ, name)
|
types += self._remove_statements(typ, name)
|
||||||
|
elif typ.isinstance(pr.WithStmt):
|
||||||
|
types += evaluator.eval_element(typ.node_from_name(name))
|
||||||
elif isinstance(typ, pr.Import):
|
elif isinstance(typ, pr.Import):
|
||||||
types += imports.ImportWrapper(self._evaluator, name).follow()
|
types += imports.ImportWrapper(self._evaluator, name).follow()
|
||||||
elif isinstance(typ, pr.TryStmt):
|
elif isinstance(typ, pr.TryStmt):
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ class Name(Leaf):
|
|||||||
elif isinstance(stmt, TryStmt):
|
elif isinstance(stmt, TryStmt):
|
||||||
return self.prev_sibling() == 'as'
|
return self.prev_sibling() == 'as'
|
||||||
else:
|
else:
|
||||||
return isinstance(stmt, (ExprStmt, Import, CompFor)) \
|
return isinstance(stmt, (ExprStmt, Import, CompFor, WithStmt)) \
|
||||||
and self in stmt.get_defined_names()
|
and self in stmt.get_defined_names()
|
||||||
|
|
||||||
def assignment_indexes(self):
|
def assignment_indexes(self):
|
||||||
@@ -918,7 +918,20 @@ class TryStmt(Flow):
|
|||||||
|
|
||||||
|
|
||||||
class WithStmt(Flow):
|
class WithStmt(Flow):
|
||||||
pass
|
def get_defined_names(self):
|
||||||
|
names = []
|
||||||
|
for with_item in self.children[1:-2:2]:
|
||||||
|
# Check with items for 'as' names.
|
||||||
|
if is_node(with_item, 'with_item'):
|
||||||
|
names += _defined_names(with_item.children[2])
|
||||||
|
return names
|
||||||
|
|
||||||
|
def node_from_name(self, name):
|
||||||
|
node = name
|
||||||
|
while True:
|
||||||
|
node = node.parent
|
||||||
|
if is_node(node, 'with_item'):
|
||||||
|
return node.children[0]
|
||||||
|
|
||||||
|
|
||||||
class Flow_old(Scope):
|
class Flow_old(Scope):
|
||||||
|
|||||||
Reference in New Issue
Block a user