[Python-bugs-list] [ python-Bugs-440707 ] doctest crashes on cross-platform .pyc

noreply@sourceforge.net noreply@sourceforge.net
Thu, 12 Jul 2001 13:27:21 -0700


Bugs item #440707, was opened at 2001-07-12 08:51
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=440707&group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: David Goodger (goodger)
Assigned to: Nobody/Anonymous (nobody)
Summary: doctest crashes on cross-platform .pyc

Initial Comment:
doctest.py raises an exception when run on true cross-
platform .pyc files (i.e., MacOS .py compiled with 
compileall.compile_dir on Windows). The problem is, 
_extract_examples splits up __doc__ strings with:

    lines = s.split("\n")

MacOS-compiled-on-Windows .pyc __doc__ strings contain 
\r, not \n. The fix is to replace the line above (line 
5 of _extract_examples) with:

    lines = s.splitlines() + ['']

The reason for the "+ ['']" is that the behavior of 
s.splitlines() is subtly different from s.split("\n"): 
splitlines() doesn't return a final null string at the 
end of, say, "one\ntwo\n", whereas split("\n") does. 
(Is this difference of behavior a bug? If not, should 
it be described in the docs?)

The "+ ['']" also circumvents errors when the 
docstring doesn't end with a newline, ie:

    """
    >>> print 'hi'
    hi"""


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

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-07-12 13:27

Message:
Logged In: YES 
user_id=6380

I'll have to look into this more, but I strongly recommend
against fixing doctest in the way you suggest.  The bug must
somehow be in the portability of .pyc files.  I'm surprised
that string literals compiled on Windows contain \r in the
.pyc file.  Are you *sure* this is what causes your problem?

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

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