1
0
forked from VimPlug/jedi

Fix issues with yield.

This commit is contained in:
Dave Halter
2017-09-01 18:38:19 +02:00
parent e2d53f51b0
commit c47f5ca68c
4 changed files with 34 additions and 2 deletions

View File

@@ -5,7 +5,10 @@ from jedi.parser_utils import clean_scope_docstring, get_doc_with_call_signature
class Context(object):
api_type = None
"""
Should be defined, otherwise the API returns empty types.
"""
"""
To be defined by subclasses.
"""
@@ -16,6 +19,12 @@ class Context(object):
self.evaluator = evaluator
self.parent_context = parent_context
@property
def api_type(self):
# By default just lower name of the class. Can and should be
# overwritten.
return self.__class__.__name__.lower()
def get_root_context(self):
context = self
while True:

View File

@@ -165,7 +165,6 @@ class GeneratorMixin(object):
class Generator(GeneratorMixin, context.Context):
"""Handling of `yield` functions."""
def __init__(self, evaluator, func_execution_context):
super(Generator, self).__init__(evaluator, parent_context=evaluator.BUILTINS)
self._func_execution_context = func_execution_context

View File

@@ -342,6 +342,11 @@ class FunctionExecutionContext(context.TreeContext):
return types
def _eval_yield(self, yield_expr):
if yield_expr.type == 'keyword':
# `yield` just yields None.
yield context.LazyKnownContext(compiled.create(self.evaluator, None))
return
node = yield_expr.children[1]
if node.type == 'yield_arg': # It must be a yield from.
cn = ContextualizedNode(self, node.children[1])

View File

@@ -179,6 +179,25 @@ gen().send()
#?
gen()()
# -----------------
# empty yield
# -----------------
def x():
yield
#? None
next(x())
#? gen()
x()
def x():
for i in range(3):
yield
#? None
next(x())
# -----------------
# yield in expression
# -----------------