From 50812b58365fd52cd4698063396aac9fea452748 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Wed, 23 May 2018 09:56:40 +0200 Subject: [PATCH] A simple yield should not cause an error, fixes #1117 --- jedi/evaluate/syntax_tree.py | 6 +++++- test/completion/generators.py | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/jedi/evaluate/syntax_tree.py b/jedi/evaluate/syntax_tree.py index fb0fd261..95ccf219 100644 --- a/jedi/evaluate/syntax_tree.py +++ b/jedi/evaluate/syntax_tree.py @@ -205,9 +205,13 @@ def eval_atom(context, atom): # For False/True/None if atom.value in ('False', 'True', 'None'): return ContextSet(compiled.builtin_from_name(context.evaluator, atom.value)) - if atom.value == 'print': + elif atom.value == 'print': # print e.g. could be evaluated like this in Python 2.7 return NO_CONTEXTS + elif atom.value == 'yield': + # Contrary to yield from, yield can just appear alone to return a + # value when used with `.send()`. + return NO_CONTEXTS assert False, 'Cannot evaluate the keyword %s' % atom elif isinstance(atom, tree.Literal): diff --git a/test/completion/generators.py b/test/completion/generators.py index 52cd714c..69e4acdb 100644 --- a/test/completion/generators.py +++ b/test/completion/generators.py @@ -208,6 +208,14 @@ def x(): #? int() next(x()) +# ----------------- +# statements +# ----------------- +def x(): + foo = yield + #? + foo + # ----------------- # yield from # -----------------