summaryrefslogtreecommitdiffstats
path: root/Objects/rangeobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/rangeobject.c')
-rw-r--r--Objects/rangeobject.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c
index 899697a..f221fde 100644
--- a/Objects/rangeobject.c
+++ b/Objects/rangeobject.c
@@ -675,6 +675,25 @@ static PyMappingMethods range_as_mapping = {
(objobjargproc)0, /* mp_ass_subscript */
};
+static int
+range_bool(rangeobject* self)
+{
+ return PyObject_IsTrue(self->length);
+}
+
+static PyNumberMethods range_as_number = {
+ 0, /* nb_add */
+ 0, /* nb_subtract */
+ 0, /* nb_multiply */
+ 0, /* nb_remainder */
+ 0, /* nb_divmod */
+ 0, /* nb_power */
+ 0, /* nb_negative */
+ 0, /* nb_positive */
+ 0, /* nb_absolute */
+ (inquiry)range_bool, /* nb_bool */
+};
+
static PyObject * range_iter(PyObject *seq);
static PyObject * range_reverse(PyObject *seq);
@@ -714,7 +733,7 @@ PyTypeObject PyRange_Type = {
0, /* tp_setattr */
0, /* tp_reserved */
(reprfunc)range_repr, /* tp_repr */
- 0, /* tp_as_number */
+ &range_as_number, /* tp_as_number */
&range_as_sequence, /* tp_as_sequence */
&range_as_mapping, /* tp_as_mapping */
(hashfunc)range_hash, /* tp_hash */