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: Document error return values for PyFloat_* and PyComplex_*
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: arnaudc, docs@python, mark.dickinson, pitrou, python-dev, skrah, vstinner
Priority: low Keywords: easy, patch

Created on 2011-12-03 12:08 by skrah, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch arnaudc, 2011-12-17 22:31 Documentation changes for c-api/real.rst and c-api/complex.rst review
patch arnaudc, 2011-12-17 23:05 review
diff_complex_rst arnaudc, 2011-12-18 01:13 review
complex.rst-2.patch arnaudc, 2011-12-18 01:50 review
Messages (14)
msg148789 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011-12-03 12:08
A couple of -1.0 error return codes aren't documented, see for
example PyFloat_AsDouble() and PyComplex_AsCComplex().
msg148790 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011-12-03 12:13
Well, it's sort of documented implicitly:  from

http://docs.python.org/c-api/intro.html#exceptions

"In general, when a function encounters an error, it sets an exception, discards any object references that it owns, and returns an error indicator.  If not documented otherwise, this indicator is either NULL or -1, depending on the function’s return type."
msg148799 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011-12-03 13:25
Good point. - I just had to figure out if the pattern

    Py_complex c = PyComplex_AsCComplex(w);
    if (c.real == -1.0 && PyErr_Occurred()) {
        ...

will always be reliable in the future. The source of PyComplex_AsCComplex()
suggests that it will, on the other hand in getargs.c the pattern isn't
used.

The passage you quoted is quite clear, so I wouldn't mind if you
close this.

I'm not sure how many people read that passage though. :)
msg148810 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-12-03 17:12
I think it's still a good idea to spell it out explicitly in each function description. The document pointed by Mark is long enough that it's easy to overlook or forget that single important statement.
msg149714 - (view) Author: Arnaud Calmettes (arnaudc) Date: 2011-12-17 22:31
Hi,

Here is the patch I propose for this issue. This is my first attempt to contribute to Python, so please don't hit me too hard if I did something wrong. :)

When browsing the source code of complexobject.c, I also noticed that the return values of the _Py_c_quot and _Py_c_pow (which return zero in case of error) weren't documented at 

http://docs.python.org/dev/c-api/complex.html#_Py_c_quot
msg149716 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-12-17 22:47
There's a typo in the patch: it's PyErr_Occurred (two r's), not PyErr_Occured.
Otherwise, looks good to me.
msg149717 - (view) Author: Arnaud Calmettes (arnaudc) Date: 2011-12-17 23:05
I fixed the typo and the markup.
msg149724 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-12-18 00:29
New changeset 68cbf6551710 by Antoine Pitrou in branch '3.2':
Issue #13522: document error return values of some float and complex C API functions.
http://hg.python.org/cpython/rev/68cbf6551710

New changeset 1f096611baf4 by Antoine Pitrou in branch 'default':
Issue #13522: document error return values of some float and complex C API functions.
http://hg.python.org/cpython/rev/1f096611baf4

New changeset 059e4d752fbe by Antoine Pitrou in branch '2.7':
Issue #13522: document error return values of some float and complex C API functions.
http://hg.python.org/cpython/rev/059e4d752fbe
msg149726 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-12-18 00:30
Committed now. Thank you for the patch!
msg149727 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-12-18 00:46
_Py_c_pow() doc is wrong:

+   If :attr:`exp.imag` is not null, or :attr:`exp.real` is negative,
+   this method returns zero and sets :c:data:`errno` to :c:data:`EDOM`.

The function only fails if num=0 and exp.real < 0 or if num=0 and exp.imag != 0.
msg149729 - (view) Author: Arnaud Calmettes (arnaudc) Date: 2011-12-18 01:13
Fixed.
msg149732 - (view) Author: Arnaud Calmettes (arnaudc) Date: 2011-12-18 01:50
Previous patch was also wrong, sorry!
msg149733 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-12-18 01:54
New changeset 67a4e8fe650e by Victor Stinner in branch 'default':
Issue #13522: Fix _Py_co_pow() documentation
http://hg.python.org/cpython/rev/67a4e8fe650e
msg149743 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-12-18 11:29
New changeset edc981ce8748 by Victor Stinner in branch '3.2':
Issue #13522: Fix _Py_co_pow() documentation
http://hg.python.org/cpython/rev/edc981ce8748

New changeset 2863470caebb by Victor Stinner in branch '2.7':
Issue #13522: Fix _Py_co_pow() documentation
http://hg.python.org/cpython/rev/2863470caebb
History
Date User Action Args
2022-04-11 14:57:24adminsetgithub: 57731
2011-12-18 11:29:06python-devsetmessages: + msg149743
2011-12-18 01:54:48vstinnersetstatus: open -> closed
resolution: fixed
2011-12-18 01:54:28python-devsetmessages: + msg149733
2011-12-18 01:50:30arnaudcsetfiles: + complex.rst-2.patch
keywords: + patch
messages: + msg149732
2011-12-18 01:13:14arnaudcsetfiles: + diff_complex_rst

messages: + msg149729
2011-12-18 00:46:36vstinnersetstatus: closed -> open

nosy: + vstinner
messages: + msg149727

resolution: fixed -> (no value)
2011-12-18 00:30:08pitrousetstatus: open -> closed
resolution: fixed
messages: + msg149726

stage: patch review -> resolved
2011-12-18 00:29:01python-devsetnosy: + python-dev
messages: + msg149724
2011-12-17 23:05:46arnaudcsetfiles: + patch

messages: + msg149717
2011-12-17 22:47:04pitrousetmessages: + msg149716
stage: needs patch -> patch review
2011-12-17 22:31:44arnaudcsetfiles: + patch
nosy: + arnaudc
messages: + msg149714

2011-12-03 17:12:11pitrousetnosy: + pitrou
messages: + msg148810
2011-12-03 13:25:51skrahsetmessages: + msg148799
2011-12-03 12:13:07mark.dickinsonsetmessages: + msg148790
versions: - Python 3.1
2011-12-03 12:08:48skrahcreate