[New-bugs-announce] [issue27719] Misleading note about "args" attribute in "User-defined Exceptions" section of tutorial

Ben Hoyt report at bugs.python.org
Tue Aug 9 12:08:46 EDT 2016


New submission from Ben Hoyt:

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!',)

----------
assignee: docs at python
components: Documentation
files: exception_args_test.py
messages: 272256
nosy: benhoyt, docs at python, georg.brandl, sbt
priority: normal
severity: normal
status: open
title: Misleading note about "args" attribute in "User-defined Exceptions" section of tutorial
versions: Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
Added file: http://bugs.python.org/file44058/exception_args_test.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27719>
_______________________________________


More information about the New-bugs-announce mailing list