At 07:24 PM 9/26/2007 +0400, Oleg Broytmann wrote:
(This seems like a "developing with Python" question and partially it is but please read on.)
I have a class that represents SQL queries. Instances of the class can be iterated over. As an SQL query doesn't know in advance if it will produce any row the class doesn't implement __len__(). Moreover, users of the class sometimes write
if sqlQuery: for row in sqlQuery: ... else: # no rows
This isn't consistent with iterators; e.g.:
x=iter() if x: print "yes"
ISTM that you should be returning "True" from __nonzero__, since you don't implement len().
- Should I consider this a bug in the logging module (and other libraries) and submit patches?
- Or should I stop raising exceptions in __nonzero__()?
#2 - Python objects should always be __nonzero__, unless they are empty containers, zeros, or otherwise specifically False. It's reasonable for libraries to expect that truth-testing an object is always safe.