This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: doctest: add an option to end examples w/ dedent
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: edloper, tim.peters
Priority: normal Keywords: patch

Created on 2004-04-10 19:56 by edloper, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
doctest_end_with_dedent.diff edloper, 2004-04-10 19:56 Diff against
Messages (4)
msg45734 - (view) Author: Edward Loper (edloper) * (Python triager) Date: 2004-04-10 19:56
A current limitation of doctest is that it can't handle 
containing blank lines, since it uses blank lines to 
detect the end of
the example.

This patch adds a new option, END_WITH_DEDENT, 
that gets around that
problem by using a dedent to detect the end of 
examples instead.  In
particular, when END_WITH_DEDENT is specified, 
the end of each
indented doctest example is marked by a dedent 
past its original
prompt (>>>).  Thus, blank lines may appear within 
the output.
However, trailing blank lines are still disallowed.  
docstring examples continue to be termined by a 
blank line (since
dedenting past the prompt is impossible).

Here's an example use:

def f():
    A doctest example with a blank line:

        >>> print 'One\n\nTwo'


    Note that ending with dedents also means that we 
can skip the
    blank lines around doctest examples if we want:
        >>> print 1
    This dedent signifies the end of the example; 
there's no need for
    a blank line.

The END_WITH_DEDENT uses the same optionflags 
system that is already

The patch was made avainst revision 1.33 of

msg45735 - (view) Author: Edward Loper (edloper) * (Python triager) Date: 2004-04-10 20:00
Logged In: YES 

If this patch looks good, I'd be happy to write a patch for 
the docs & test cases.
msg45736 - (view) Author: Edward Loper (edloper) * (Python triager) Date: 2004-04-11 15:15
Logged In: YES 

This patch is probably mutually exclusive with patch 
#933238 [1], since they both have the same goal: to 
allow blank lines in doctest output. I thought of this 
solution first, but I think I prefer the other patch. 
Here's a comparison of pros and cons of this patch vs 

[-] it needs a special option to turn it on
[-] it doesn't handles trailing blank lines
[-] it will break external tools like epytext and 
restructuredtext that look for doctest blocks.
[+] the user doesn't have to manually add blank line 
msg45737 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-06-01 00:23
Logged In: YES 

Rejecting this one; let's focus on your other patch instead.
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40137
2004-04-10 19:56:43edlopercreate