forked from VimPlug/jedi
_remove_statements beautified
This commit is contained in:
@@ -158,8 +158,10 @@ class NameFinder(object):
|
|||||||
typ = name.parent
|
typ = name.parent
|
||||||
if typ.isinstance(pr.ForFlow):
|
if typ.isinstance(pr.ForFlow):
|
||||||
types += self._handle_for_loops(typ)
|
types += self._handle_for_loops(typ)
|
||||||
|
elif isinstance(typ, pr.Param):
|
||||||
|
types += self._eval_param(typ)
|
||||||
elif typ.isinstance(pr.Statement):
|
elif typ.isinstance(pr.Statement):
|
||||||
types += self._remove_statements(typ, resolve_decorator)
|
types += self._remove_statements(typ)
|
||||||
else:
|
else:
|
||||||
if isinstance(typ, pr.Class):
|
if isinstance(typ, pr.Class):
|
||||||
typ = er.Class(self._evaluator, typ)
|
typ = er.Class(self._evaluator, typ)
|
||||||
@@ -170,7 +172,7 @@ class NameFinder(object):
|
|||||||
types.append(typ)
|
types.append(typ)
|
||||||
return types
|
return types
|
||||||
|
|
||||||
def _remove_statements(self, r, resolve_decorator=False):
|
def _remove_statements(self, stmt):
|
||||||
"""
|
"""
|
||||||
This is the part where statements are being stripped.
|
This is the part where statements are being stripped.
|
||||||
|
|
||||||
@@ -178,38 +180,31 @@ class NameFinder(object):
|
|||||||
evaluated.
|
evaluated.
|
||||||
"""
|
"""
|
||||||
evaluator = self._evaluator
|
evaluator = self._evaluator
|
||||||
res_new = []
|
types = []
|
||||||
add = []
|
if stmt.is_global():
|
||||||
check_instance = None
|
# global keyword handling.
|
||||||
if isinstance(r, er.InstanceElement) and r.is_class_var:
|
for token_name in stmt.token_list[1:]:
|
||||||
check_instance = r.instance
|
|
||||||
r = r.var
|
|
||||||
|
|
||||||
# Global variables handling.
|
|
||||||
if r.is_global():
|
|
||||||
for token_name in r.token_list[1:]:
|
|
||||||
if isinstance(token_name, pr.Name):
|
if isinstance(token_name, pr.Name):
|
||||||
return evaluator.find_types(r.parent, str(token_name))
|
return evaluator.find_types(stmt.parent, str(token_name))
|
||||||
else:
|
else:
|
||||||
# generated objects are used within executions, but these
|
|
||||||
# objects are in functions, and we have to dynamically
|
|
||||||
# execute first.
|
|
||||||
if isinstance(r, pr.Param):
|
|
||||||
return self._eval_param(r)
|
|
||||||
# Remove the statement docstr stuff for now, that has to be
|
# Remove the statement docstr stuff for now, that has to be
|
||||||
# implemented with the evaluator class.
|
# implemented with the evaluator class.
|
||||||
#if r.docstr:
|
#if stmt.docstr:
|
||||||
#res_new.append(r)
|
#res_new.append(stmt)
|
||||||
|
|
||||||
add += evaluator.eval_statement(r, seek_name=self.name_str)
|
check_instance = None
|
||||||
|
if isinstance(stmt, er.InstanceElement) and stmt.is_class_var:
|
||||||
|
check_instance = stmt.instance
|
||||||
|
stmt = stmt.var
|
||||||
|
|
||||||
if check_instance is not None:
|
types += evaluator.eval_statement(stmt, seek_name=self.name_str)
|
||||||
# class renames
|
|
||||||
add = [er.InstanceElement(evaluator, check_instance, a, True)
|
|
||||||
if isinstance(a, (er.Function, pr.Function))
|
|
||||||
else a for a in add]
|
|
||||||
|
|
||||||
return res_new + add
|
if check_instance is not None:
|
||||||
|
# class renames
|
||||||
|
types = [er.InstanceElement(evaluator, check_instance, a, True)
|
||||||
|
if isinstance(a, (er.Function, pr.Function))
|
||||||
|
else a for a in types]
|
||||||
|
return types
|
||||||
|
|
||||||
def _eval_param(self, r):
|
def _eval_param(self, r):
|
||||||
evaluator = self._evaluator
|
evaluator = self._evaluator
|
||||||
@@ -222,10 +217,10 @@ class NameFinder(object):
|
|||||||
if func is not None \
|
if func is not None \
|
||||||
and isinstance(until(), pr.Class) \
|
and isinstance(until(), pr.Class) \
|
||||||
and r.position_nr == 0:
|
and r.position_nr == 0:
|
||||||
# This is where self gets added - this happens at another
|
# This is where self gets added - this happens at another place, if
|
||||||
# place, if the var_args are clear. But sometimes the class is
|
# the var_args are clear. But sometimes the class is not known.
|
||||||
# not known. Therefore add a new instance for self. Otherwise
|
# Therefore add a new instance for self. Otherwise take the
|
||||||
# take the existing.
|
# existing.
|
||||||
if isinstance(self.scope, er.InstanceElement):
|
if isinstance(self.scope, er.InstanceElement):
|
||||||
res_new.append(self.scope.instance)
|
res_new.append(self.scope.instance)
|
||||||
else:
|
else:
|
||||||
@@ -234,9 +229,8 @@ class NameFinder(object):
|
|||||||
res_new.append(inst)
|
res_new.append(inst)
|
||||||
return res_new
|
return res_new
|
||||||
|
|
||||||
# Instances are typically faked, if the instance is not
|
# Instances are typically faked, if the instance is not called from
|
||||||
# called from outside. Here we check it for __init__
|
# outside. Here we check it for __init__ functions and return.
|
||||||
# functions and return.
|
|
||||||
if isinstance(func, er.InstanceElement) \
|
if isinstance(func, er.InstanceElement) \
|
||||||
and func.instance.is_generated \
|
and func.instance.is_generated \
|
||||||
and hasattr(func, 'name') \
|
and hasattr(func, 'name') \
|
||||||
|
|||||||
Reference in New Issue
Block a user