- Objects supporting __len__() use (len > 0) for boolean representation,
which normally makes sense but as the match iterator count is often
zero despite the iterator actually existing and returning something,
and breaks existing code (rpmlint at least)
- Adding a __bool__() (known as __nonzero__() in Python < 3) method
returning true for non-NULL iterator fixes this and gives more
meaningful answers than pre 4.8.0 which simply always returned True
return s->mi ? rpmdbGetIteratorCount(s->mi) : 0;
}
+static int rpmmi_bool(rpmmiObject *s)
+{
+ return (s->mi != NULL);
+}
+
PyMappingMethods rpmmi_as_mapping = {
(lenfunc) rpmmi_length, /* mp_length */
0,
};
+static PyNumberMethods rpmmi_as_number = {
+ 0, /* nb_add */
+ 0, /* nb_subtract */
+ 0, /* nb_multiply */
+ 0, /* nb_divide */
+ 0, /* nb_remainder */
+ 0, /* nb_divmod */
+ 0, /* nb_power */
+ 0, /* nb_negative */
+ 0, /* nb_positive */
+ 0, /* nb_absolute */
+ (inquiry)rpmmi_bool, /* nb_bool/nonzero */
+};
+
static char rpmmi_doc[] =
"";
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
- 0, /* tp_as_number */
+ &rpmmi_as_number, /* tp_as_number */
0, /* tp_as_sequence */
&rpmmi_as_mapping, /* tp_as_mapping */
0, /* tp_hash */