As others noted, a tuple with elements in it is not tested as False
, which is one of the reasons why you can return None
, and not (None, None)
. However, you can write a set of subcategories that is checked as False
, even if it has elements, overriding its __nonzero__()
method.
class falsetuple(tuple): def __nonzero__(self): return False
Then you can return falsetuple((None, None))
when there is no value available. In fact, you can always return the same falsetuple
.
I donโt necessarily recommend that you do this, in fact I have serious concerns about violating this agreement, Iโm just saying that the veracity of non-empty tuples is not necessarily the reason for not returning the tuple.
kindall Aug 16 '11 at 18:44 2011-08-16 18:44
source share