From 69afc2482a97d557d8610fe0c066e529e391e474 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Tue, 7 Jan 2014 13:25:30 +0100 Subject: [PATCH] nicer _remove_statements --- jedi/evaluate/finder.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index 5fc897a4..a03ec72c 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -211,20 +211,15 @@ class NameFinder(object): res_new = [] func = r.parent - exc = pr.Class, pr.Function - until = lambda: func.parent.get_parent_until(exc) + cls = func.parent.get_parent_until((pr.Class, pr.Function)) - if func is not None \ - and isinstance(until(), pr.Class) \ - and r.position_nr == 0: - # This is where self gets added - this happens at another place, if - # the var_args are clear. But sometimes the class is not known. - # Therefore add a new instance for self. Otherwise take the - # existing. + if isinstance(cls, pr.Class) and r.position_nr == 0: + # This is where we add self - if it has never been + # instantiated. if isinstance(self.scope, er.InstanceElement): res_new.append(self.scope.instance) else: - for inst in self._evaluator.execute(er.Class(self._evaluator, until())): + for inst in evaluator.execute(er.Class(evaluator, cls)): inst.is_generated = True res_new.append(inst) return res_new @@ -232,19 +227,16 @@ class NameFinder(object): # Instances are typically faked, if the instance is not called from # outside. Here we check it for __init__ functions and return. if isinstance(func, er.InstanceElement) \ - and func.instance.is_generated \ - and hasattr(func, 'name') \ - and str(func.name) == '__init__' \ - and r.position_nr > 0: # 0 would be self + and func.instance.is_generated and str(func.name) == '__init__': r = func.var.params[r.position_nr] - # add docstring knowledge + # Add docstring knowledge. doc_params = docstrings.follow_param(evaluator, r) if doc_params: - res_new += doc_params - return res_new + return doc_params if not r.is_generated: + # Param owns no information itself. res_new += dynamic.search_params(evaluator, r) if not res_new: c = r.expression_list()[0]