Equivalent code to the bool() built-in function

Daniel Kluev dan.kluev at gmail.com
Sun Apr 17 06:11:55 EDT 2011


On Sun, Apr 17, 2011 at 7:38 PM, candide <candide at free.invalid> wrote:
> I could't imagine a builtin function having a so trivial implementation.

As it was pointed out, its not function, its type,
SETBUILTIN("bool",                  &PyBool_Type);

While its __new__ is indeed trivial (in essence, it just calls
PyObject_IsTrue), it also provides needed comparison ops, repr and
other magic methods for the type.
You can check Objects/boolobject.c in python repository if its
implementation is interesting for you.

-- 
With best regards,
Daniel Kluev



More information about the Python-list mailing list