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: Py_RETURN_BOOL() convenience macro
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.2
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, jon, loewis
Priority: normal Keywords: patch

Created on 2009-09-27 00:04 by jon, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Py_RETURN_BOOL.patch jon, 2009-09-27 00:04 Py_RETURN_BOOL implementation
Py_RETURN_BOOL.examples.patch jon, 2009-09-27 00:06 Py_RETURN_BOOL examples
Py_RETURN_BOOL.doc.patch jon, 2009-09-27 00:12 Py_RETURN_BOOL documentation
Messages (6)
msg93164 - (view) Author: Jon Parise (jon) Date: 2009-09-27 00:04
I've sometimes found it useful to define a convenience macro named
Py_RETURN_BOOL(x) which is essentially:

#define Py_RETURN_BOOL(x) if (x) Py_RETURN_TRUE; else Py_RETURN_FALSE

It's useful for implementing functions which return Boolean values based
on simple conditions.

I think it's readable and doesn't detract from regular program flow,
although it does hide the condition behind a macro, which detracts a bit
from the code's debug-ability.
msg93165 - (view) Author: Jon Parise (jon) Date: 2009-09-27 00:06
Also attached is a short set of examples of how this macro could be used
in the Python source tree.
msg93166 - (view) Author: Jon Parise (jon) Date: 2009-09-27 00:12
Also attached is a small documentation patch.
msg93169 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-09-27 07:26
-1. What's wrong with writing

   return PyBool_FromLong(x);
msg93170 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-09-27 14:10
I agree with Martin; PyBool_FromLong is sufficient.
msg93186 - (view) Author: Jon Parise (jon) Date: 2009-09-27 21:30
I agree, as well.

I didn't consider PyBool_FromLong() because I was expecting to solve the
problem using a macro, but that is clearly not the best approach here
(insignificant function call overhead aside).
History
Date User Action Args
2022-04-11 14:56:53adminsetgithub: 51253
2009-09-27 21:30:11jonsetmessages: + msg93186
2009-09-27 14:10:47benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg93170

resolution: rejected
2009-09-27 07:26:01loewissetnosy: + loewis
messages: + msg93169
2009-09-27 00:12:07jonsetfiles: + Py_RETURN_BOOL.doc.patch

messages: + msg93166
2009-09-27 00:06:12jonsetfiles: + Py_RETURN_BOOL.examples.patch

messages: + msg93165
2009-09-27 00:04:58joncreate