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.
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:53
admin
set
github: 51253
2009-09-27 21:30:11
jon
set
messages: +
2009-09-27 14:10:47
benjamin.peterson
set
status: open -> closednosy: + benjamin.petersonmessages: + resolution: rejected