[ python-Bugs-1172785 ] doctest.script_from_examples() result sometimes un-exec-able

SourceForge.net noreply at sourceforge.net
Mon Jun 27 00:24:02 CEST 2005

Bugs item #1172785, was opened at 2005-03-29 22:50
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting: 

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Jonathan E. Guyer (jguyer)
>Assigned to: Reinhold Birkenfeld (birkenfeld)
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


>Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-06-27 00:24

Logged In: YES 

Thanks for the report, this is fixed as of Lib/doctest.py
r1.123, r1.120.2.2.


You can respond by visiting: 

More information about the Python-bugs-list mailing list