[ python-Bugs-1172785 ] doctest.script_from_examples() result
sometimes un-exec-able
SourceForge.net
noreply at sourceforge.net
Tue Mar 29 22:50:53 CEST 2005
Bugs item #1172785, was opened at 2005-03-29 15:50
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1172785&group_id=5470
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Jonathan E. Guyer (jguyer)
Assigned to: Nobody/Anonymous (nobody)
Summary: doctest.script_from_examples() result sometimes un-exec-able
Initial Comment:
doctest.script_from_examples() can sometimes return results that
cannot be passed to exec. The docstring for script_from_examples()
itself is an example:
guyer% python2.4
Python 2.4 (#1, Mar 10 2005, 18:08:38)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1671)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> text = '''
... Here are examples of simple math.
... Python has super accurate integer addition
... >>> 2 + 2
... 5
...
... And very friendly error messages:
...
... >>> 1/0
... To Infinity
... And
... Beyond
...
... You can use logic if you want:
...
... >>> if 0:
... ... blay
... ... blah
... ...
...
... Ho hum
... '''
>>> exec doctest.script_from_examples(text)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 21
# Ho hum
^
SyntaxError: invalid syntax
The issue seems to be the lack of trailing '\n', which is documented
as required by compile(), although not for exec.
We never saw a problem with this in Python 2.3's doctest, probably
because comment lines, such as "Ho hum", were stripped out and
apparently adequate '\n' were appended.
Python 2.4 on Mac OS X 10.3.8
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1172785&group_id=5470
More information about the Python-bugs-list
mailing list