forked from VimPlug/jedi
Separate some Generator stuff.
This commit is contained in:
@@ -155,9 +155,9 @@ def _check_for_exception_catch(evaluator, jedi_obj, exception, payload=None):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_hasattr(stmt):
|
def check_hasattr(node):
|
||||||
expression_list = stmt.expression_list()
|
|
||||||
try:
|
try:
|
||||||
|
assert False
|
||||||
assert len(expression_list) == 1
|
assert len(expression_list) == 1
|
||||||
call = expression_list[0]
|
call = expression_list[0]
|
||||||
assert isinstance(call, pr.Call) and str(call.name) == 'hasattr'
|
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):
|
if obj.isinstance(pr.TryStmt) and check_try_for_except(obj):
|
||||||
return True
|
return True
|
||||||
# hasattr check
|
# hasattr check
|
||||||
if exception == AttributeError and obj.command in ('if', 'while'):
|
if exception == AttributeError and obj.isinstance(pr.IfStmt, pr.WhileStmt):
|
||||||
if obj.inputs and check_hasattr(obj.inputs[0]):
|
if check_hasattr(obj.children[1]):
|
||||||
return True
|
return True
|
||||||
obj = obj.parent
|
obj = obj.parent
|
||||||
|
|
||||||
|
|||||||
@@ -40,14 +40,7 @@ class IterableWrapper(pr.Base):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class Generator(use_metaclass(CachedMetaClass, IterableWrapper)):
|
class GeneratorMixin(object):
|
||||||
"""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
|
|
||||||
|
|
||||||
@underscore_memoization
|
@underscore_memoization
|
||||||
def _get_defined_names(self):
|
def _get_defined_names(self):
|
||||||
"""
|
"""
|
||||||
@@ -65,6 +58,15 @@ class Generator(use_metaclass(CachedMetaClass, IterableWrapper)):
|
|||||||
def scope_names_generator(self, position=None):
|
def scope_names_generator(self, position=None):
|
||||||
yield self, self._get_defined_names()
|
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):
|
def iter_content(self):
|
||||||
""" returns the content of __iter__ """
|
""" returns the content of __iter__ """
|
||||||
# Directly execute it, because with a normal call to py__call__ a
|
# 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):
|
def iter_content(self):
|
||||||
return self._evaluator.eval_statement_element(self.comprehension)
|
return self._evaluator.eval_statement_element(self.comprehension)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user