[python] Threads/Messages inconsistencies

Patrick Totzke patricktotzke at googlemail.com
Sat Dec 24 01:44:47 PST 2011


Hi,

I noticed some inconsistencies in the way the bindings
treat Threads and Messages
which in my opinion should look and behave alike.

1. There is no Query.count_threads as an equivalent to
   Query.count_messages, although there seems to be a function
   `notmuch_query_count_threads` offered by the library

2. The docstring of Query.count_messages falsely states it's
   return value is a Messages object, when it in fact returns a long.

3. The docstring of Threads contains a line 
   "number_of_msgs = len(threads)"
   which should be
   "number_of_threads = len(threads)"

4. Threads.__len__ smells wrong: I have 10 messages in 9 threads in my inbox,

   pazz at brick:~$ python
   Python 2.7.2+ (default, Oct  4 2011, 20:06:09) 
   [GCC 4.6.1] on linux2
   Type "help", "copyright", "credits" or "license" for more information.
   >>> import notmuch
   >>> d=notmuch.Database()
   >>> q=d.create_query('is:inbox and not is:killed')
   >>> 
   >>> q.count_messages()
   10L
   >>> len(list(q.search_messages()))
   10
   >>> 
   >>> len(q.search_threads())
   10
   >>> list(q.search_threads())
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/home/pazz/.local/lib/python2.7/site-packages/notmuch/thread.py", line 121, in next
       raise NotmuchError(STATUS.NOT_INITIALIZED)
   notmuch.globals.NotInitializedError: Operation on uninitialized object impossible.
   >>> 

   The python session above speaks for itself I believe but this is what I consider
   bad behaviour, just to make sure:
   * why does list(q.search_messages() go through and list(q.search_threads() fails?
   * why does len(q.search_threads()) return 10 and not 9 as expected?



I have corrected the docstrings myself and copied the code from Query.count_messages
to provide a Query.count_threads. The two patches can be pulled from pazz.github.org/notmuch.
The count_threads patch doesn't work however, which is really surprising as the code
is straightforward. When I do a import notmuch after applying the patch, I get:

  AttributeError: /usr/local/lib/libnotmuch.so.2: undefined symbol: notmuch_query_count_threads

Best,
/p


More information about the notmuch mailing list