[IPython-dev] Doctests & Python 3

Thomas Kluyver takowl at gmail.com
Tue Aug 23 17:07:53 EDT 2011


I'd like to get the doctests working on Python 3, but I'm not sure about the
best way to do it. I think most of the problems are with print statements,
and it seems distribute doesn't recognise IPython doctests in order to
convert them during the build step (as it does with regular doctests). A few
options:

1. Use a regex to transform print statements in the doctest parser.
2. Transform any doctests using print where they are defined, with a helper
function/decorator. Slight performance penalty to starting IPython, because
we'll be transforming a number of doctests as we import modules. On the plus
side, examples in docstrings will automatically be correct in Python 3.
Regex transform is a bit trickier than 1, because the source is mixed up
with prompts etc.
3. Add print statements to doctests as the output of a doctest_print helper
function (so doctest_print("x", file="outfile") returns "print >>outfile, x"
on Python 2). Much the same pros and cons as 2.
4. Write all doctests with print as a function, and run them on Python 2
with "from __future__ import print_function". No performance penalty when
loading IPython, but more confusing for anyone reading the code.

I've not got a strong feeling about which is best. I'd probably lean towards
1 or 2, but I'd like some other opinions.

Thanks,
Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20110823/846faab2/attachment.html>


More information about the IPython-dev mailing list