[IPython-dev] Doctests & Python 3
Tue Aug 23 16:33:14 CDT 2011
There is a -d option to 2to3 that should do the necessary
transformations for you.
Also, if you don't actually use the fact that it's a function, you
don't have to import print_function from __future__ to use the
print(1) syntax in Python 2.
On Tue, Aug 23, 2011 at 3:07 PM, Thomas Kluyver <firstname.lastname@example.org> wrote:
> 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
> 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.
> IPython-dev mailing list
More information about the IPython-dev