[pypy-svn] r72338 - in pypy/trunk/pypy/interpreter: . astcompiler astcompiler/test
benjamin at codespeak.net
benjamin at codespeak.net
Thu Mar 18 01:55:45 CET 2010
Author: benjamin
Date: Thu Mar 18 01:55:43 2010
New Revision: 72338
Modified:
pypy/trunk/pypy/interpreter/astcompiler/codegen.py
pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py
pypy/trunk/pypy/interpreter/pycode.py
Log:
don't allow lambdas to have docstrings and prevent non-strings from becoming docstrings
Modified: pypy/trunk/pypy/interpreter/astcompiler/codegen.py
==============================================================================
--- pypy/trunk/pypy/interpreter/astcompiler/codegen.py (original)
+++ pypy/trunk/pypy/interpreter/astcompiler/codegen.py Thu Mar 18 01:55:43 2010
@@ -1289,6 +1289,8 @@
if lam.args.args:
self._handle_nested_args(lam.args.args)
self.argcount = len(lam.args.args)
+ # Prevent a string from being the first constant and thus a docstring.
+ self.add_const(self.space.w_None)
lam.body.walkabout(self)
self.emit_op(ops.RETURN_VALUE)
Modified: pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py
==============================================================================
--- pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py (original)
+++ pypy/trunk/pypy/interpreter/astcompiler/test/test_compiler.py Thu Mar 18 01:55:43 2010
@@ -317,6 +317,9 @@
for source, expected in [
('''def foo(): return 1''', None),
('''class foo: pass''', None),
+ ('''foo = lambda: 4''', None),
+ ('''foo = lambda: "foo"''', None),
+ ('''def foo(): 4''', None),
('''class foo: "foo"''', "foo"),
('''def foo():
"""foo docstring"""
Modified: pypy/trunk/pypy/interpreter/pycode.py
==============================================================================
--- pypy/trunk/pypy/interpreter/pycode.py (original)
+++ pypy/trunk/pypy/interpreter/pycode.py Thu Mar 18 01:55:43 2010
@@ -220,9 +220,10 @@
def getdocstring(self, space):
if self.co_consts_w: # it is probably never empty
- return self.co_consts_w[0]
- else:
- return space.w_None
+ w_first = self.co_consts_w[0]
+ if space.is_true(space.isinstance(w_first, space.w_basestring)):
+ return w_first
+ return space.w_None
def getjoinpoints(self):
"""Compute the bytecode positions that are potential join points
More information about the Pypy-commit
mailing list