forked from VimPlug/jedi
Support generator returns when used with yield from.
This commit is contained in:
@@ -42,12 +42,11 @@ from jedi.parser_utils import get_comp_fors
|
||||
|
||||
|
||||
class AbstractIterableMixin(object):
|
||||
@property
|
||||
def name(self):
|
||||
return compiled.CompiledContextName(self, self.array_type)
|
||||
def py__stop_iteration_returns(self):
|
||||
return ContextSet(compiled.builtin_from_name(self.evaluator, u'None'))
|
||||
|
||||
|
||||
class GeneratorBase(BuiltinOverwrite):
|
||||
class GeneratorBase(BuiltinOverwrite, AbstractIterableMixin):
|
||||
array_type = None
|
||||
special_object_identifier = u'GENERATOR_OBJECT'
|
||||
|
||||
@@ -71,6 +70,9 @@ class Generator(GeneratorBase):
|
||||
def py__iter__(self):
|
||||
return self._func_execution_context.get_yield_lazy_contexts()
|
||||
|
||||
def py__stop_iteration_returns(self):
|
||||
return self._func_execution_context.get_return_values()
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s of %s>" % (type(self).__name__, self._func_execution_context)
|
||||
|
||||
@@ -182,6 +184,10 @@ class ComprehensionMixin(object):
|
||||
class Sequence(BuiltinOverwrite, AbstractIterableMixin):
|
||||
api_type = u'instance'
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return compiled.CompiledContextName(self, self.array_type)
|
||||
|
||||
@memoize_method
|
||||
def get_object(self):
|
||||
compiled_obj = compiled.builtin_from_name(self.evaluator, self.array_type)
|
||||
|
||||
@@ -124,6 +124,23 @@ def eval_node(context, element):
|
||||
return eval_node(context, element.children[0])
|
||||
elif typ == 'annassign':
|
||||
return pep0484._evaluate_for_annotation(context, element.children[1])
|
||||
elif typ == 'yield_expr':
|
||||
if len(element.children) and element.children[1].type == 'yield_arg':
|
||||
# Implies that it's a yield from.
|
||||
element = element.children[1].children[1]
|
||||
generators = context.eval_node(element)
|
||||
results = ContextSet()
|
||||
for generator in generators:
|
||||
try:
|
||||
method = generator.py__stop_iteration_returns
|
||||
except AttributeError:
|
||||
debug.warning('%s is not actually a generator', generator)
|
||||
else:
|
||||
results |= method()
|
||||
return results
|
||||
|
||||
# Generator.send() is not implemented.
|
||||
return NO_CONTEXTS
|
||||
else:
|
||||
return eval_or_test(context, element)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user