Commit 8e45b42d authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #833 from undingen/generators2

support yield statements inside lambdas
parents 93243be1 7ebe9720
......@@ -1650,7 +1650,7 @@ extern "C" int PyNumber_Check(PyObject* obj) noexcept {
assert(obj && obj->cls);
// Our check, since we don't currently fill in tp_as_number:
if (PyFloat_Check(obj) || PyFloat_Check(obj) || PyFloat_Check(obj))
if (PyInt_Check(obj) || PyLong_Check(obj) || PyFloat_Check(obj))
return true;
// The CPython check:
......
......@@ -73,13 +73,13 @@ SourceInfo::SourceInfo(BoxedModule* m, ScopingAnalysis* scoping, FutureFlags fut
switch (ast->type) {
case AST_TYPE::ClassDef:
case AST_TYPE::Lambda:
case AST_TYPE::Module:
case AST_TYPE::Expression:
case AST_TYPE::Suite:
is_generator = false;
break;
case AST_TYPE::FunctionDef:
case AST_TYPE::Lambda:
is_generator = containsYield(ast);
break;
default:
......
......@@ -1178,7 +1178,7 @@ private:
push_back(makeExpr(new AST_LangPrimitive(AST_LangPrimitive::UNCACHE_EXC_INFO)));
if (root_type != AST_TYPE::FunctionDef)
if (root_type != AST_TYPE::FunctionDef && root_type != AST_TYPE::Lambda)
raiseExcHelper(SyntaxError, "'yield' outside function");
return makeLoad(node_name, node);
......
......@@ -128,3 +128,9 @@ try:
g.next()
except Exception as e:
print type(e), e # StopIteration
x = lambda: (yield 1)
print list(x())
x = lambda: ((yield 1), (yield 2))
print list(x())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment