[Python-ideas] Special-case 3.x 'print x' SyntaxError
Steven D'Aprano
steve at pearwood.info
Mon Sep 15 15:46:40 CEST 2014
On Mon, Sep 15, 2014 at 11:50:26AM +0200, Mike Müller wrote:
> In general, I think the single most useful improvement for beginners are
> better hints in error message about what possibly went wrong.
>
> If this goes beyond syntax errors, adding a switch to turn this off might
> be useful. Just in case somebody actually scrapes messages or your doctests
> break.
The exact exception message is not a part of the public API of Python
built-ins or the standard library, so any code which relies on that is
wrong. Error messages are subject to change without notice. As for doc
tests, the doctest module has a directive specifically for ignoring the
exception error message:
https://docs.python.org/3/library/doctest.html#doctest.IGNORE_EXCEPTION_DETAIL
Just add #doctest:+IGNORE_EXCEPTION_DETAIL to your test, and the
message will be ignored.
--
Steven
More information about the Python-ideas
mailing list