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.
Created on 2012年06月08日 01:22 by r.david.murray, last changed 2022年04月11日 14:57 by admin.
| Messages (11) | |||
|---|---|---|---|
| msg162513 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2012年06月08日 01:22 | |
And I wish I knew what those were. |
|||
| msg162540 - (view) | Author: Éric Araujo (eric.araujo) * (Python committer) | Date: 2012年06月08日 18:03 | |
I don’t understand the request. |
|||
| msg162541 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2012年06月08日 18:08 | |
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. |
|||
| msg164033 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2012年06月26日 04:33 | |
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. |
|||
| msg164076 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2012年06月26日 13:43 | |
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. |
|||
| msg164434 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2012年06月30日 23:08 | |
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? |
|||
| msg171039 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2012年09月23日 14:03 | |
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". |
|||
| msg171065 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2012年09月23日 17:23 | |
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. |
|||
| msg183034 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2013年02月26日 08:51 | |
I'm removing the "devguide" component and update the title accordingly. |
|||
| msg380713 - (view) | Author: Irit Katriel (iritkatriel) * (Python committer) | Date: 2020年11月10日 20:58 | |
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 |
|||
| msg380739 - (view) | Author: Vedran Čačić (veky) * | Date: 2020年11月11日 07:31 | |
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. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:31 | admin | set | github: 59239 |
| 2020年11月11日 07:31:11 | veky | set | nosy:
+ veky messages: + msg380739 |
| 2020年11月10日 20:58:21 | iritkatriel | set | nosy:
+ iritkatriel messages: + msg380713 versions: + Python 3.8, Python 3.9, Python 3.10, - Python 2.7, Python 3.2, Python 3.3 |
| 2013年02月26日 08:51:19 | ezio.melotti | set | messages:
+ msg183034 components: + Documentation, - Devguide title: Devguide should document best practices for stdlib exceptions -> Document best practices for exceptions |
| 2012年09月23日 17:26:53 | chris.jerdonek | set | nosy:
+ chris.jerdonek |
| 2012年09月23日 17:23:13 | terry.reedy | set | messages: + msg171065 |
| 2012年09月23日 14:03:06 | ezio.melotti | set | messages: + msg171039 |
| 2012年06月30日 23:08:09 | terry.reedy | set | nosy:
+ terry.reedy messages: + msg164434 |
| 2012年06月29日 18:57:58 | tshepang | set | nosy:
+ tshepang |
| 2012年06月26日 13:43:24 | r.david.murray | set | status: closed -> open title: tutorial should use best practices in user defined exceptions section -> Devguide should document best practices for stdlib exceptions messages: + msg164076 components: + Devguide, - Documentation resolution: later -> |
| 2012年06月26日 04:33:25 | rhettinger | set | status: open -> closed nosy: + rhettinger messages: + msg164033 resolution: later |
| 2012年06月15日 08:09:59 | ezio.melotti | set | nosy:
+ ezio.melotti |
| 2012年06月08日 18:40:40 | belopolsky | set | nosy:
+ belopolsky |
| 2012年06月08日 18:40:09 | belopolsky | set | title: tutorial should use best practices in user defined execeptions section -> tutorial should use best practices in user defined exceptions section |
| 2012年06月08日 18:08:51 | r.david.murray | set | messages: + msg162541 |
| 2012年06月08日 18:03:26 | eric.araujo | set | nosy:
+ eric.araujo messages: + msg162540 |
| 2012年06月08日 08:50:03 | hynek | set | nosy:
+ hynek |
| 2012年06月08日 01:22:04 | r.david.murray | create | |