Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6dd2cb

Browse files
committed
Merged revisions 79034 via svnmerge from
svn+ssh://[email protected]/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 ........
1 parent 8fbddf1 commit e6dd2cb

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

Lib/test/test_compile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ def f():
292292
f1, f2 = f()
293293
self.assertNotEqual(id(f1.__code__), id(f2.__code__))
294294

295-
## def test_unicode_encoding(self):
296-
## code = "# -*- coding: utf-8 -*-\npass\n"
297-
## self.assertRaises(SyntaxError, compile, code, "tmp", "exec")
295+
def test_lambda_doc(self):
296+
l = lambda: "foo"
297+
self.assertIsNone(l.__doc__)
298298

299299
def test_subscripts(self):
300300
# SF bug 1448804

Python/compile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,11 @@ compiler_lambda(struct compiler *c, expr_ty e)
16601660
if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
16611661
return 0;
16621662

1663+
/* Make None the first constant, so the lambda can't have a
1664+
docstring. */
1665+
if (compiler_add_o(c, c->u->u_consts, Py_None) < 0)
1666+
return 0;
1667+
16631668
c->u->u_argcount = asdl_seq_LEN(args->args);
16641669
c->u->u_kwonlyargcount = asdl_seq_LEN(args->kwonlyargs);
16651670
VISIT_IN_SCOPE(c, expr, e->v.Lambda.body);

0 commit comments

Comments
 (0)