[Python-bugs-list] [ python-Bugs-473864 ] doctest expects spurios space

noreply@sourceforge.net noreply@sourceforge.net
Mon, 22 Oct 2001 19:25:26 -0700


Bugs item #473864, was opened at 2001-10-22 18:36
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=473864&group_id=5470

Category: Python Library
>Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
>Assigned to: Tim Peters (tim_one)
Summary: doctest expects spurios space 

Initial Comment:
When trying something like this:

>>> for k in ((1, 2), (3, 4)):
...  print k,
... 
(1, 2) (3, 4)

doctest expects an extra leading space in the output.
See the attached file for some more details.

Sverker



----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2001-10-22 19:25

Message:
Logged In: YES 
user_id=31435

You're screwing yourself with the trailing comma in the 
*preceding* example.  This sets the magical "softspace" 
attribute on doctest's stdout proxy, which causes Python to 
generate a leading space on the *next* example's first line 
of output.

This is repaired now in current CVS doctest

Lib/doctest.py; new revision: 1.21

via destroying the softspace attr after every example.  
Before 2.2, don't write examples like this.  If you *have* 
to use a trailing comma in a "print" example, use an empty 
print statement afterwards to ensure the last output line 
is terminated correctly.  So, e.g.,

>>> for i in range(2):
...     print i,
... print
0 1

instead of

>>> for i range(2):
...    print i,
0 1

Then it will work correctly under all versions of doctest.  
At heart, doctest can't tell whether or not example output 
lines actually terminated with a newline (since the 
examples doctest sees are taken from Python files, it 
*always* look like they have a terminating newline).

----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2001-10-22 18:47

Message:
Logged In: NO 

I forgot my email before when I sent in the bug report.
Interested to know if it is a real bug or if it is just me
and my system.. sverker.is@home.se

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=473864&group_id=5470