forked from VimPlug/jedi
Fix issues with yield.
This commit is contained in:
@@ -5,7 +5,10 @@ from jedi.parser_utils import clean_scope_docstring, get_doc_with_call_signature
|
|||||||
|
|
||||||
|
|
||||||
class Context(object):
|
class Context(object):
|
||||||
api_type = None
|
"""
|
||||||
|
Should be defined, otherwise the API returns empty types.
|
||||||
|
"""
|
||||||
|
|
||||||
"""
|
"""
|
||||||
To be defined by subclasses.
|
To be defined by subclasses.
|
||||||
"""
|
"""
|
||||||
@@ -16,6 +19,12 @@ class Context(object):
|
|||||||
self.evaluator = evaluator
|
self.evaluator = evaluator
|
||||||
self.parent_context = parent_context
|
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):
|
def get_root_context(self):
|
||||||
context = self
|
context = self
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
@@ -165,7 +165,6 @@ class GeneratorMixin(object):
|
|||||||
|
|
||||||
class Generator(GeneratorMixin, context.Context):
|
class Generator(GeneratorMixin, context.Context):
|
||||||
"""Handling of `yield` functions."""
|
"""Handling of `yield` functions."""
|
||||||
|
|
||||||
def __init__(self, evaluator, func_execution_context):
|
def __init__(self, evaluator, func_execution_context):
|
||||||
super(Generator, self).__init__(evaluator, parent_context=evaluator.BUILTINS)
|
super(Generator, self).__init__(evaluator, parent_context=evaluator.BUILTINS)
|
||||||
self._func_execution_context = func_execution_context
|
self._func_execution_context = func_execution_context
|
||||||
|
|||||||
@@ -342,6 +342,11 @@ class FunctionExecutionContext(context.TreeContext):
|
|||||||
return types
|
return types
|
||||||
|
|
||||||
def _eval_yield(self, yield_expr):
|
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]
|
node = yield_expr.children[1]
|
||||||
if node.type == 'yield_arg': # It must be a yield from.
|
if node.type == 'yield_arg': # It must be a yield from.
|
||||||
cn = ContextualizedNode(self, node.children[1])
|
cn = ContextualizedNode(self, node.children[1])
|
||||||
|
|||||||
@@ -179,6 +179,25 @@ gen().send()
|
|||||||
#?
|
#?
|
||||||
gen()()
|
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
|
# yield in expression
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user