diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 1de9027a88f..90d6b87b50f 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -292,9 +292,9 @@ if 1: f1, f2 = f() self.assertNotEqual(id(f1.__code__), id(f2.__code__)) -## def test_unicode_encoding(self): -## code = "# -*- coding: utf-8 -*-\npass\n" -## self.assertRaises(SyntaxError, compile, code, "tmp", "exec") + def test_lambda_doc(self): + l = lambda: "foo" + self.assertIsNone(l.__doc__) def test_subscripts(self): # SF bug 1448804 diff --git a/Python/compile.c b/Python/compile.c index 2c58d449b5e..62fa46c6158 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1660,6 +1660,11 @@ compiler_lambda(struct compiler *c, expr_ty e) if (!compiler_enter_scope(c, name, (void *)e, e->lineno)) return 0; + /* Make None the first constant, so the lambda can't have a + docstring. */ + if (compiler_add_o(c, c->u->u_consts, Py_None) < 0) + return 0; + c->u->u_argcount = asdl_seq_LEN(args->args); c->u->u_kwonlyargcount = asdl_seq_LEN(args->kwonlyargs); VISIT_IN_SCOPE(c, expr, e->v.Lambda.body);