diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2012-04-30 19:12:36 +0200 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2012-04-30 19:25:16 +0200 |
commit | 7f74a400d197dac5cdf36960f68f63ce3eeff486 (patch) | |
tree | 9dcedef71864d1bd683e3fda85ee13b80a2deed2 /bindings/python/notmuch/threads.py | |
parent | 162687a99e412098729d639ed7bc27f01372cb84 (diff) |
python: cleanup the __nonzero__ implementations
Cleanup the code, reword the docstring and use the same implementation
in the Threads, Tags and Messages classes.
__nonzero__ implements truth value testing. If __nonzero__ is not
implemented, the python runtime would fall back to `len(..) > 0` thus
exhausting the iterator.
Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
Diffstat (limited to 'bindings/python/notmuch/threads.py')
-rw-r--r-- | bindings/python/notmuch/threads.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/bindings/python/notmuch/threads.py b/bindings/python/notmuch/threads.py index a6441640..d2e0a910 100644 --- a/bindings/python/notmuch/threads.py +++ b/bindings/python/notmuch/threads.py @@ -157,18 +157,15 @@ class Threads(Python3StringMixIn): return i def __nonzero__(self): - """Check if :class:`Threads` contains at least one more valid thread - - The existence of this function makes 'if Threads: foo' work, as - that will implicitely call len() exhausting the iterator if - __nonzero__ does not exist. This function makes `bool(Threads())` - work repeatedly. - - :return: True if there is at least one more thread in the - Iterator, False if not. None on a "Out-of-memory" error. - """ - return self._threads is not None and \ - self._valid(self._threads) > 0 + ''' + Implement truth value testing. If __nonzero__ is not + implemented, the python runtime would fall back to `len(..) > + 0` thus exhausting the iterator. + + :returns: True if the wrapped iterator has at least one more object + left. + ''' + return self._threads and self._valid(self._threads) _destroy = nmlib.notmuch_threads_destroy _destroy.argtypes = [NotmuchThreadsP] |