Merged revisions 79034 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79034 | benjamin.peterson | 2010-03-17 15:41:42 -0500 (Wed, 17 Mar 2010) | 1 line

  prevent lambda functions from having docstrings #8164
........
This commit is contained in:
Benjamin Peterson 2010-03-17 20:56:58 +00:00
parent 8fbddf15ea
commit e6dd2cb63d
2 changed files with 8 additions and 3 deletions

View File

@ -292,9 +292,9 @@ if 1:
f1, f2 = f() f1, f2 = f()
self.assertNotEqual(id(f1.__code__), id(f2.__code__)) self.assertNotEqual(id(f1.__code__), id(f2.__code__))
## def test_unicode_encoding(self): def test_lambda_doc(self):
## code = "# -*- coding: utf-8 -*-\npass\n" l = lambda: "foo"
## self.assertRaises(SyntaxError, compile, code, "tmp", "exec") self.assertIsNone(l.__doc__)
def test_subscripts(self): def test_subscripts(self):
# SF bug 1448804 # SF bug 1448804

View File

@ -1660,6 +1660,11 @@ compiler_lambda(struct compiler *c, expr_ty e)
if (!compiler_enter_scope(c, name, (void *)e, e->lineno)) if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
return 0; 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_argcount = asdl_seq_LEN(args->args);
c->u->u_kwonlyargcount = asdl_seq_LEN(args->kwonlyargs); c->u->u_kwonlyargcount = asdl_seq_LEN(args->kwonlyargs);
VISIT_IN_SCOPE(c, expr, e->v.Lambda.body); VISIT_IN_SCOPE(c, expr, e->v.Lambda.body);