Message217568
Hi Jesús,
I believe the patch should have this behavior:
a) If the database is closed, raise an exception.
b) If database is empty, return False.
c) If database has any entry, return True. Fast and simply checking if the database has at least a single record.
The 0/1 appears to be converted to Py_TRUE/Py_FALSE in PyObject_IsTrue() in boolobject.c.
For background, here's the code path I'm seeing:
bool_new(...) (in Objects/boolobject.c)
...
ok = PyObject_IsTrue(obj) (in Objects/object.c)
...
return PyBool_FromLong(ok)
Looking at PyObject_IsTrue is informative. It shows that since tp_as_number->nb_bool is defined (as dbm_bool), it is used instead of the old default of tp_as_mapping->mp_length.
I'm still learning CPython, and I'm not sure if everything goes through bool_new(), but I think this makes sense. If you see more places I can/should look for details here, let me know. |
|
Date |
User |
Action |
Args |
2014-04-30 04:02:11 | eolson | set | recipients:
+ eolson, jafo, jcea, johansen, ysj.ray |
2014-04-30 04:02:11 | eolson | set | messageid: <1398830531.88.0.778290121593.issue2159@psf.upfronthosting.co.za> |
2014-04-30 04:02:11 | eolson | link | issue2159 messages |
2014-04-30 04:02:11 | eolson | create | |
|