This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eolson
Recipients eolson, jafo, jcea, johansen, ysj.ray
Date 2014-04-30.04:02:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1398830531.88.0.778290121593.issue2159@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-04-30 04:02:11eolsonsetrecipients: + eolson, jafo, jcea, johansen, ysj.ray
2014-04-30 04:02:11eolsonsetmessageid: <1398830531.88.0.778290121593.issue2159@psf.upfronthosting.co.za>
2014-04-30 04:02:11eolsonlinkissue2159 messages
2014-04-30 04:02:11eolsoncreate