[Python-3000] removing exception .args (original) (raw)

Brett Cannon brett at python.org
Sun Jul 22 02:46:21 CEST 2007


On 7/21/07, Andrew Dalke <dalke at dalkescientific.com> wrote:

Posting here a expansion of a short discussion I had after Guido's keynote at EuroPython. In this email I propose eliminating the ".args" attribute from the Exception type. It's not useful, and supporting it correctly is complicated enough that it's often not supported correctly

This was originally proposed in PEP 352. This was the reason for the existence of the 'message' attribute as introduced in Python 2.5.. At PyCon 2007 I actually removed 'args' (see the p3yk_no_args_on_exc branch in svn: http://svn.python.org/view/python/branches/p3yk_no_args_on_exc/).

But after making everyone at PyCon suffer through my swearing and frustration and talking with python-dev (and thus should be in the python-dev/python-3000 archives), the decision was made to not remove it (which is why 'message' is deprecated in Python 2.6). This was because the removal at the C level is very painful. There are many places within the code where a tuple is passed to various C functions that expect that tuple to be treated as multiple arguments to the exception constructor.

But changing the semantics of a C function has already been labeled a no-no. So one would have to remove the C functions that construct exceptions with arguments and use a new one that only expects a single argument so not to have unexpected semantics. That sucks because those functions are all over.

In the branch I just stuck the tuple into the 'message' attribute, but that caused its own issues as output was now a little funky since everything was considered a tuple, including single arguments.

So while I totally understand the desire to ditch 'args' and just have 'message', doing so thoroughly and in any reasonable way that is not painful is not easy thanks to the C API.

-Brett



More information about the Python-3000 mailing list