make _remove_statements smaller

This commit is contained in:
Dave Halter
2014-01-07 11:32:20 +01:00
parent 821d2b9220
commit 66ec389f5c
+11 -12
View File
@@ -158,8 +158,17 @@ 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)
else: elif typ.isinstance(pr.Statement):
types += self._remove_statements(typ, resolve_decorator) types += self._remove_statements(typ, resolve_decorator)
else:
r = typ
if isinstance(r, pr.Class):
r = er.Class(self._evaluator, r)
elif isinstance(r, pr.Function):
r = er.Function(self._evaluator, r)
if r.isinstance(er.Function) and resolve_decorator:
r = r.get_decorated_func()
types.append(r)
return types return types
def _remove_statements(self, r, resolve_decorator=False): def _remove_statements(self, r, resolve_decorator=False):
@@ -171,7 +180,6 @@ class NameFinder(object):
""" """
evaluator = self._evaluator evaluator = self._evaluator
res_new = [] res_new = []
if r.isinstance(pr.Statement):
add = [] add = []
check_instance = None check_instance = None
if isinstance(r, er.InstanceElement) and r.is_class_var: if isinstance(r, er.InstanceElement) and r.is_class_var:
@@ -247,17 +255,8 @@ class NameFinder(object):
add = [er.InstanceElement(evaluator, check_instance, a, True) add = [er.InstanceElement(evaluator, check_instance, a, True)
if isinstance(a, (er.Function, pr.Function)) if isinstance(a, (er.Function, pr.Function))
else a for a in add] else a for a in add]
res_new += add
else:
if isinstance(r, pr.Class):
r = er.Class(self._evaluator, r)
elif isinstance(r, pr.Function):
r = er.Function(self._evaluator, r)
if r.isinstance(er.Function) and resolve_decorator:
r = r.get_decorated_func()
res_new.append(r)
return res_new return res_new + add
def _handle_for_loops(self, loop): def _handle_for_loops(self, loop):
# Take the first statement (for has always only # Take the first statement (for has always only