msg93439 - (view) |
Author: (lekma) * |
Date: 2009-10-02 11:14 |
It would be nice to have an obvious/simple way to document C exceptions (especially when using the autoexception feature from Sphinx). Something along: PyObject *PyErr_Create(char *name, const char *doc) Creates and returns a new exception object. This behaves like PyErr_Create2() with base set to NULL. PyObject *PyErr_Create2(char *name, const char *doc, PyObject *base) Creates and returns a new exception object. The name argument must be the name of the new exception, a C string of the form module.class. If doc is non-NULL, it will be used to define the docstring for the exception. if base is NULL, it creates a class object derived from Exception (accessible in C as PyExc_Exception). for py3k the signatures would be: PyObject *PyErr_Create(const char *name, const char *doc) PyObject *PyErr_Create2(const char *name, const char *doc, PyObject *base) Internally, these functions would pass a dict to PyErr_NewException with the key '__doc__' set to doc. If there is support for this, I can provide patches for trunk and py3k. |
|
|
msg93448 - (view) |
Author: (lekma) * |
Date: 2009-10-02 17:23 |
First attempt at implementing this. Diff is against trunk. |
|
|
msg93449 - (view) |
Author: (lekma) * |
Date: 2009-10-02 17:24 |
The same against py3k |
|
|
msg93484 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2009-10-03 09:30 |
Sounds like a useful new API. Two comments: * The version without *base* is not needed. Passing an explicit NULL for *base* is easy enough. * The name "PyErr_Create" is needlessly different from "PyErr_NewException". Something like "PyErr_NewExceptionWithDoc" is better. |
|
|
msg93526 - (view) |
Author: (lekma) * |
Date: 2009-10-04 09:34 |
Even though I don't fully agree with your comments here is a second attempt addressing them, against trunk. For the record, I think that the signature difference is enough to warrant a name that is a clear cut from PyErr_NewException. And in the spirit of the Py_InitModule and PyModule_Create families of function I thought the most common/simple form should stand out from the more complete one. But, hey, I'm happy if this gets in (in any form :). |
|
|
msg93527 - (view) |
Author: (lekma) * |
Date: 2009-10-04 09:36 |
Same as previous against py3k |
|
|
msg96667 - (view) |
Author: (lekma) * |
Date: 2009-12-20 09:21 |
Is there any chance that this will make it in? |
|
|
msg96675 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2009-12-20 14:06 |
Since it's a new CAPI I think it should probably be discussed briefly on python-dev. |
|
|
msg96676 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2009-12-20 14:08 |
> Since it's a new CAPI I think it should probably be discussed briefly on > python-dev. So do I. |
|
|
msg96677 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2009-12-20 14:09 |
Also, what about tests? |
|
|
msg96679 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2009-12-20 14:13 |
Funnily, I already did ask on python-dev, and only got one (+1) answer from Brett. I was going to add it some time when I have more cycles for Python. |
|
|
msg96680 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2009-12-20 14:14 |
Yes, I'd say that counts as a brief discussion :) |
|
|
msg96682 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2009-12-20 14:23 |
One nitpick: Python/errors.c uses tabs for indentation, your patch should as well. |
|
|
msg96740 - (view) |
Author: (lekma) * |
Date: 2009-12-21 11:50 |
patch against trunk: - fix tabs issue (I hope) - add test |
|
|
msg96741 - (view) |
Author: (lekma) * |
Date: 2009-12-21 11:52 |
The same with a simpler test. I leave it up to you guys to choose which one is the best. |
|
|
msg96943 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2009-12-28 08:36 |
Thanks for the patch! I rewrote the C function a bit to also take a dict argument, and added a test for that. Committed in r77088. Will merge to py3k. |
|
|
msg96946 - (view) |
Author: (lekma) * |
Date: 2009-12-28 14:08 |
> Thanks for the patch! I rewrote the C function a bit to also take a dict > argument, and added a test for that. Committed in r77088. Will merge > to py3k. Great! Thanks to all for the help! |
|
|
msg97009 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2009-12-29 21:41 |
lekma, this patch is now listed in the 2.7 "what's new" document as contributed by "the lekma user", please tell us if you want your name there. |
|
|
msg97022 - (view) |
Author: (lekma) * |
Date: 2009-12-30 07:26 |
> lekma, this patch is now listed in the 2.7 "what's new" document as > contributed by "the lekma user", please tell us if you want your name > there. Nope, that's ok (it's perfect). |
|
|