homepage

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.

classification
Title: initproc return value is unclear
Type: behavior Stage: resolved
Components: Documentation, Extension Modules Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: amaury.forgeotdarc, docs@python, james, python-dev, r.david.murray, zbysz
Priority: normal Keywords: easy, patch

Created on 2013年03月07日 17:12 by zbysz, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue_17380.patch james, 2015年04月13日 01:14 documentation patch for Doc/extending/newtypes.rst review
Messages (7)
msg183689 - (view) Author: Zbyszek Jędrzejewski-Szmek (zbysz) * Date: 2013年03月07日 17:12
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-data-and-methods-to-the-basic-example 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.
msg183737 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2013年03月08日 14:30
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();
msg183738 - (view) Author: Zbyszek Jędrzejewski-Szmek (zbysz) * Date: 2013年03月08日 14:44
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
msg184077 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2013年03月13日 12:43
Note that all these cases are compatible with "tp_init returns 0 on success and -1 on error".
msg240580 - (view) Author: James Powell (james) Date: 2015年04月13日 01:14
See attached patch to clarify this in the docs.
msg240582 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015年04月13日 01:54
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 
msg240583 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015年04月13日 01:55
Thanks, James.
History
Date User Action Args
2022年04月11日 14:57:42adminsetgithub: 61582
2015年04月13日 01:55:19r.david.murraysetstatus: open -> closed
resolution: fixed
messages: + msg240583

stage: resolved
2015年04月13日 01:54:08python-devsetnosy: + python-dev
messages: + msg240582
2015年04月13日 01:18:09jamessetnosy: + r.david.murray
2015年04月13日 01:14:00jamessetfiles: + issue_17380.patch
keywords: + patch
messages: + msg240580
2015年04月13日 01:12:13jamessetnosy: + james
2014年04月14日 19:19:30akuchlingsetkeywords: + easy
2013年03月13日 12:43:52amaury.forgeotdarcsetmessages: + msg184077
2013年03月08日 14:44:33zbyszsetmessages: + msg183738
2013年03月08日 14:30:18amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg183737
2013年03月07日 17:12:17zbyszcreate

AltStyle によって変換されたページ (->オリジナル) /