diff --git a/jedi/evaluate/analysis.py b/jedi/evaluate/analysis.py index 9045231e..6eb81b44 100644 --- a/jedi/evaluate/analysis.py +++ b/jedi/evaluate/analysis.py @@ -155,9 +155,9 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None): return True return False - def check_hasattr(stmt): - expression_list = stmt.expression_list() + def check_hasattr(node): try: + assert False assert len(expression_list) == 1 call = expression_list[0] assert isinstance(call, pr.Call) and str(call.name) == 'hasattr' @@ -183,8 +183,8 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None): if obj.isinstance(pr.TryStmt) and check_try_for_except(obj): return True # hasattr check - if exception == AttributeError and obj.command in ('if', 'while'): - if obj.inputs and check_hasattr(obj.inputs[0]): + if exception == AttributeError and obj.isinstance(pr.IfStmt, pr.WhileStmt): + if check_hasattr(obj.children[1]): return True obj = obj.parent diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index 56faf1c4..ed2e86ec 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -40,14 +40,7 @@ class IterableWrapper(pr.Base): return False -class Generator(use_metaclass(CachedMetaClass, IterableWrapper)): - """Handling of `yield` functions.""" - def __init__(self, evaluator, func, var_args): - super(Generator, self).__init__() - self._evaluator = evaluator - self.func = func - self.var_args = var_args - +class GeneratorMixin(object): @underscore_memoization def _get_defined_names(self): """ @@ -65,6 +58,15 @@ class Generator(use_metaclass(CachedMetaClass, IterableWrapper)): def scope_names_generator(self, position=None): yield self, self._get_defined_names() + +class Generator(use_metaclass(CachedMetaClass, IterableWrapper, GeneratorMixin)): + """Handling of `yield` functions.""" + def __init__(self, evaluator, func, var_args): + super(Generator, self).__init__() + self._evaluator = evaluator + self.func = func + self.var_args = var_args + def iter_content(self): """ returns the content of __iter__ """ # Directly execute it, because with a normal call to py__call__ a @@ -153,7 +155,7 @@ class ListComprehension(Comprehension): -class GeneratorComprehension(Comprehension): +class GeneratorComprehension(Comprehension, GeneratorMixin): def iter_content(self): return self._evaluator.eval_statement_element(self.comprehension)