[issue17380] initproc return value is unclear
New submission from Zbyszek Jędrzejewski-Szmek: initproc is declared to return an int, but what returned values mean is not documented. Noddy_init in http://docs.python.org/3/extending/newtypes.html?highlight=initproc#adding-d... can be seen to return 0 on success and -1 on error, but that's about it. Also, when I wrote a function which return 1 on error, on every second invocation the exception would be ignored: static int Reader_init(Reader *self, PyObject *args, PyObject *keywds) { ... if (flags && path) { PyErr_SetString(PyExc_ValueError, "cannot use both flags and path"); return 1; } ... }
obj(123, '/tmp') obj(123, '/tmp') ... ValueError obj(123, '/tmp') obj(123, '/tmp') ... ValueError
I'm not sure how to interpret this since I couldn't find the documentation for the expected value. ---------- assignee: docs@python components: Documentation, Extension Modules messages: 183689 nosy: docs@python, zbysz priority: normal severity: normal status: open title: initproc return value is unclear type: behavior versions: Python 2.7, Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17380> _______________________________________
Amaury Forgeot d'Arc added the comment: The return value for error conditions should be -1. - typeobject.c checks with "< 0" - in _iomodule.c, there is "== -1" - and pygobject/gobject/gobjectmodule.c just does:: if (...tp_init(...)) PyErr_Print(); ---------- nosy: +amaury.forgeotdarc _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17380> _______________________________________
Zbyszek Jędrzejewski-Szmek added the comment: On Fri, Mar 08, 2013 at 02:30:18PM +0000, Amaury Forgeot d'Arc wrote:
Amaury Forgeot d'Arc added the comment:
The return value for error conditions should be -1.
- typeobject.c checks with "< 0" - in _iomodule.c, there is "== -1" - and pygobject/gobject/gobjectmodule.c just does:: if (...tp_init(...)) PyErr_Print();
That's not very nice. Would it make sense to unify those checks, e.g. for "initproc() < 0"? Than the documentation could be updated. Zbyszek ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17380> _______________________________________
Amaury Forgeot d'Arc added the comment: Note that all these cases are compatible with "tp_init returns 0 on success and -1 on error". ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17380> _______________________________________
Changes by A.M. Kuchling <amk@amk.ca>: ---------- keywords: +easy _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17380> _______________________________________
Changes by James Powell <james@dontusethiscode.com>: ---------- nosy: +james _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17380> _______________________________________
James Powell added the comment: See attached patch to clarify this in the docs. ---------- keywords: +patch Added file: http://bugs.python.org/file38910/issue_17380.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17380> _______________________________________
Changes by James Powell <james@dontusethiscode.com>: ---------- nosy: +r.david.murray _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17380> _______________________________________
Roundup Robot added the comment: New changeset c6dc1e0db7f0 by R David Murray in branch '3.4': #17380: Document tp_init return value in extending docs. https://hg.python.org/cpython/rev/c6dc1e0db7f0 New changeset d74ede4bbf81 by R David Murray in branch 'default': Merge: #17380: Document tp_init return value in extending docs. https://hg.python.org/cpython/rev/d74ede4bbf81 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17380> _______________________________________
R. David Murray added the comment: Thanks, James. ---------- resolution: -> fixed stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue17380> _______________________________________
participants (6)
-
A.M. Kuchling
-
Amaury Forgeot d'Arc
-
James Powell
-
R. David Murray
-
Roundup Robot
-
Zbyszek Jędrzejewski-Szmek