[issue15034] tutorial should use best practices in user defined execeptions section
New submission from R. David Murray <rdmurray@bitdance.com>: And I wish I knew what those were. ---------- assignee: docs@python components: Documentation messages: 162513 nosy: docs@python, r.david.murray priority: normal severity: normal stage: needs patch status: open title: tutorial should use best practices in user defined execeptions section type: behavior versions: Python 2.7, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Changes by Hynek Schlawack <hs@ox.cx>: ---------- nosy: +hynek _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Éric Araujo <merwok@netwok.org> added the comment: I don’t understand the request. ---------- nosy: +eric.araujo _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
R. David Murray <rdmurray@bitdance.com> added the comment: The obvious example is that the tutorial makes no mention of calling 'super' in __init__. I'm also aware that there are issues of pickleability that arise if you do things one way, but do not arise if you do things another way. But I don't know the details, and I'd like to see the tutorial show an example of the *best* way to write a user defined exception so that they behave like the built in Python exceptions. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Changes by Alexander Belopolsky <alexander.belopolsky@gmail.com>: ---------- title: tutorial should use best practices in user defined execeptions section -> tutorial should use best practices in user defined exceptions section _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Changes by Alexander Belopolsky <alexander.belopolsky@gmail.com>: ---------- nosy: +belopolsky _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- nosy: +ezio.melotti _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: This seems more like a Stack Overflow question or fodder for a blog post. When such best practices become well known and agreed upon, they can be added toa HOWTO document. The tutorial is problematic because beginners start there and sprinkling the nuances of super() throughout the tutorial will only get in the way of the main learning points for a given section. ---------- nosy: +rhettinger resolution: -> later status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
R. David Murray <rdmurray@bitdance.com> added the comment: OK, let's move this, then. I asked the question because I'd like to know what the best practice is for exceptions in the stdlib. This is an area in which we have made quite a bit of progress recently (ie: the work done on exceptions for Python3, and PEP 3151), but I think there is still a lack of documentation (and possibly consensus?) on best practices for the stdlib. ---------- components: +Devguide -Documentation resolution: later -> status: closed -> open title: tutorial should use best practices in user defined exceptions section -> Devguide should document best practices for stdlib exceptions _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Changes by Tshepang Lekhonkhobe <tshepang@gmail.com>: ---------- nosy: +tshepang _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: I agree with Raymond that this, especially super() is not tutorial material. I agree with David that we need something somewhere else. Just today a commit was pushed about IOException subclasses causing problems because they have an __init__ but don't call super(). (Something like that.) I had no idea about this issue. The stdlib has things like "class ModException(Exception): pass". Is that okay because it does *not* have __init__ override? ---------- nosy: +terry.reedy _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Ezio Melotti added the comment: I'm not sure this belongs to the devguide. Ideally the best way to do it should be documented in the docs. This doesn't necessary mean it should be in the tutorial, but if the way documented in the tutorial is "wrong", I'd rather tell users "this is the right way, do like this and don't worry about the details right now (but follow this link if you want to know more)" than "use this wrongish way that is simple but will break as soon as you start doing something more complex". ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Terry J. Reedy added the comment: I think the Library Manual's chapter 5 on exceptions, currently called Built-in Exceptions, would be a good place for a section on subclassing exceptions. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Changes by Chris Jerdonek <chris.jerdonek@gmail.com>: ---------- nosy: +cjerdonek _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Ezio Melotti added the comment: I'm removing the "devguide" component and update the title accordingly. ---------- components: +Documentation -Devguide title: Devguide should document best practices for stdlib exceptions -> Document best practices for exceptions _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue15034> _______________________________________
Irit Katriel <iritkatriel@yahoo.com> added the comment: There are examples in the tutorial where super().__init__ is not called, like here: https://docs.python.org/3/tutorial/errors.html#user-defined-exceptions ---------- nosy: +iritkatriel versions: +Python 3.10, Python 3.8, Python 3.9 -Python 2.7, Python 3.2, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue15034> _______________________________________
Vedran Čačić <vedgar@gmail.com> added the comment: Terry: of course, if a method is not overridden, there's no need to call super()'s method, since the only thing it would do is call the same thing that would be called without overriding. But of course, if Exception's __init__ does anything, then super() should be called from the overrridden method. ---------- nosy: +veky _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue15034> _______________________________________
participants (11)
-
Alexander Belopolsky
-
Chris Jerdonek
-
Ezio Melotti
-
Hynek Schlawack
-
Irit Katriel
-
R. David Murray
-
Raymond Hettinger
-
Terry J. Reedy
-
Tshepang Lekhonkhobe
-
Vedran Čačić
-
Éric Araujo