[Python-Dev] 3-way result of PyObject_IsTrue() considered PITA

Raymond Hettinger Raymond Hettinger" <python@rcn.com
Wed, 16 Apr 2003 01:56:45 -0400

The docs for PyObject_IsTrue() promise that the "function 
always succeeds".  But in reality it can return an error 
result if an underlying method returns an error.

The calls in ceval.c and elsewhere are cluttered and slowed
by trying to handle all three possibilities.  In other places
(like bltinmodule.c and pyexpat.c), the result is used directly
in an "if(result)" clause that ignores the possibility of an
error return.

Instead of fixing the docs, do you guys think there may
be merit in returning False whenever explicit Truth isn't 
found?  Favoring practicality over silent error passage?

This would simplify the use of the function, honor the
promise in the docs, and match usage in code that had not 
considered an error result. The function and its callers will 
end-up a little smaller, a little faster, and a little more consistent.
Also, reasoning about truth values will be a tad simpler.

Note, similar thoughts also apply to PyObject_Not().

Raymond Hettinger
Pythonistas Against Three Valued Predicates