Commit 8ea1fb82 authored by Tres Seaver's avatar Tres Seaver

Merge fix for issue #945.

parent af83b41e
......@@ -46,6 +46,9 @@ Zope Changes
Bugs fixed
- Collector #945: Allow adding empty PythonScript instances
programmatically.
- Updated doc/UNITTEST.txt and lib/python/Testing/README.txt to
reflect progress made since UNITTEST.txt was originally written.
......
......@@ -220,12 +220,13 @@ class RFunction(RModule):
# Stitch the body code into the function.
f.code.nodes = body_code.node.nodes
f.name = self.name
# Look for a docstring.
stmt1 = f.code.nodes[0]
if (isinstance(stmt1, ast.Discard) and
isinstance(stmt1.expr, ast.Const) and
isinstance(stmt1.expr.value, str)):
f.doc = stmt1.expr.value
# Look for a docstring, if there are any nodes at all
if len(f.code.nodes) > 0:
stmt1 = f.code.nodes[0]
if (isinstance(stmt1, ast.Discard) and
isinstance(stmt1.expr, ast.Const) and
isinstance(stmt1.expr.value, str)):
f.doc = stmt1.expr.value
# The caller may specify that certain variables are globals
# so that they can be referenced before a local assignment.
# The only known example is the variables context, container,
......
......@@ -13,7 +13,7 @@ import unittest
from RestrictedPython import compile_restricted, PrintCollector
from RestrictedPython.Eval import RestrictionCapableEval
from RestrictedPython.tests import before_and_after, restricted_module, verify
from RestrictedPython.RCompile import RModule
from RestrictedPython.RCompile import RModule, RFunction
try:
__file__
......@@ -437,6 +437,12 @@ class RestrictionTests(unittest.TestCase):
co = self._compile_file("lambda.py")
exec co in {}, {}
def checkEmpty(self):
rf = RFunction("", "", "issue945", "empty.py", {})
rf.parse()
rf2 = RFunction("", "# still empty\n\n# by", "issue945", "empty.py", {})
rf2.parse()
def checkSyntaxError(self):
err = ("def f(x, y):\n"
" if x, y < 2 + 1:\n"
......
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