Stefan Behnel wrote:
That's simple to do. However, doctests in user documentation are much harder
to write in a portable way, as all that overhead of (e.g.) encoding byte
strings to unicode strings for normalised output comparison is very
distracting for readers, so it would be much better if you could just say
"this is a doctest in Py3 syntax" or "in Py2 syntax", and have doctest do the
rest for you at runtime.

Doctest just uses 'exec' under the covers though - the only way for it to run code using non-native syntax would be for it to be able to invoke a non-native parser and then run the resulting AST directly, or for it to invoke 2to3 on the docstring.

Sphinx (the tool used to build the Python docs) gets around this by allowing code to be included in the doc source that is used when running the doctests, but hidden when generating output for human consumption (HTML, PDF, etc)

Cheers,
Nick.

--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
            http://www.boredomandlaziness.org
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to