Stéphane Wirtel | cbb6484 | 2019-05-17 11:55:34 +0200 | [diff] [blame] | 1 | .. highlight:: c |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 2 | |
| 3 | .. _boolobjects: |
| 4 | |
| 5 | Boolean Objects |
| 6 | --------------- |
| 7 | |
| 8 | Booleans in Python are implemented as a subclass of integers. There are only |
| 9 | two booleans, :const:`Py_False` and :const:`Py_True`. As such, the normal |
| 10 | creation and deletion functions don't apply to booleans. The following macros |
| 11 | are available, however. |
| 12 | |
| 13 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 14 | .. c:function:: int PyBool_Check(PyObject *o) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 15 | |
Antonio Cuni | 315fc52 | 2021-01-06 12:38:26 +0100 | [diff] [blame] | 16 | Return true if *o* is of type :c:data:`PyBool_Type`. This function always |
| 17 | succeeds. |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 18 | |
| 19 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 20 | .. c:var:: PyObject* Py_False |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 21 | |
| 22 | The Python ``False`` object. This object has no methods. It needs to be |
| 23 | treated just like any other object with respect to reference counts. |
| 24 | |
| 25 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 26 | .. c:var:: PyObject* Py_True |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 27 | |
| 28 | The Python ``True`` object. This object has no methods. It needs to be treated |
| 29 | just like any other object with respect to reference counts. |
| 30 | |
| 31 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 32 | .. c:macro:: Py_RETURN_FALSE |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 33 | |
| 34 | Return :const:`Py_False` from a function, properly incrementing its reference |
| 35 | count. |
| 36 | |
| 37 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 38 | .. c:macro:: Py_RETURN_TRUE |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 39 | |
| 40 | Return :const:`Py_True` from a function, properly incrementing its reference |
| 41 | count. |
| 42 | |
| 43 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 44 | .. c:function:: PyObject* PyBool_FromLong(long v) |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 45 | |
| 46 | Return a new reference to :const:`Py_True` or :const:`Py_False` depending on the |
| 47 | truth value of *v*. |