1
0
forked from VimPlug/jedi

Fix except statements names.

This commit is contained in:
Dave Halter
2014-11-13 01:02:45 +01:00
parent 2fc67b97e5
commit 1ab67ebbba
2 changed files with 9 additions and 14 deletions

View File

@@ -301,6 +301,13 @@ class NameFinder(object):
types += self._remove_statements(typ, name)
elif isinstance(typ, pr.Import):
types += imports.ImportWrapper(self._evaluator, name).follow()
elif isinstance(typ, pr.TryStmt):
# TODO an exception can also be a tuple. Check for those.
# TODO check for types that are not classes and add it to
# the static analysis report.
exceptions = evaluator.eval_element(name.prev_sibling().prev_sibling())
types = list(chain.from_iterable(
evaluator.execute(t) for t in exceptions))
else:
if typ.isinstance(er.Function) and resolve_decorator:
typ = typ.get_decorated_func()
@@ -333,20 +340,6 @@ class NameFinder(object):
types += evaluator.eval_statement(stmt, seek_name=name)
# check for `except X as y` usages, because y needs to be instantiated.
p = stmt.parent
# TODO this looks really hacky, improve parser representation!
if isinstance(p, pr.Flow) and p.command == 'except' and p.inputs:
as_names = p.inputs[0].as_names
try:
if as_names[0] == name:
# TODO check for types that are not classes and add it to
# the static analysis report.
types = list(chain.from_iterable(
evaluator.execute(t) for t in types))
except IndexError:
pass
if check_instance is not None:
# class renames
types = [er.get_instance_el(evaluator, check_instance, a, True)

View File

@@ -275,6 +275,8 @@ class Name(Leaf):
return self.start_pos < stmt.children[2].start_pos
elif isinstance(stmt, Param):
return self == stmt.get_name()
elif isinstance(stmt, TryStmt):
return self.prev_sibling() == 'as'
else:
return isinstance(stmt, (ExprStmt, Import, CompFor)) \
and self in stmt.get_defined_names()