This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author benhoyt
Recipients benhoyt, docs@python, georg.brandl, sbt
Date 2016-08-09.16:08:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1470758926.96.0.219997040874.issue27719@psf.upfronthosting.co.za>
In-reply-to
Content
In the official tutorial in the "User-defined Exceptions" section (https://docs.python.org/3.5/tutorial/errors.html#user-defined-exceptions) there's a note about a user-defined Exception subclass as follows:

"In this example, the default __init__() of Exception has been overridden. The new behavior simply creates the value attribute. This replaces the default behavior of creating the args attribute."

That last sentence is wrong: it used to be that way (it is in Python 2.x and I believe in Python pre 3.2), but now the implementation of BaseException.__new__ now sets args, so even when you override __init__ and don't call super() args is set. I think that's what you want, so I'm putting this down to a documentation bug. I think the sentence "This replaces the default behavior of creating the args attribute." should simply be removed (BaseException.__init__ basically does nothing now).

This change happened for Python 3.3 and was backported to Python 3.2. See also:

* The relevant part of BaseException.__new__ in the CPython codebase: https://github.com/python/cpython/blob/601ee5fab5df81a25611da0667030de531c1cda9/Objects/exceptions.c#L44-L48
* The issue where this behaviour was changed: http://bugs.python.org/issue1692335
* The commit where it was changed: https://hg.python.org/cpython/rev/68e2690a471d (on GitHub at https://github.com/python/cpython/commit/a71a87e695b05a67bd22c6ac74311b1f56f3932e)
* You can repro this and confirm that "args" is definitely set with the attached script:

$ python exception_args_test.py 
sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)
Error args: ('error!',)
History
Date User Action Args
2016-08-09 16:08:47benhoytsetrecipients: + benhoyt, georg.brandl, docs@python, sbt
2016-08-09 16:08:46benhoytsetmessageid: <1470758926.96.0.219997040874.issue27719@psf.upfronthosting.co.za>
2016-08-09 16:08:46benhoytlinkissue27719 messages
2016-08-09 16:08:46benhoytcreate