From: Floris Bruynooghe <flub@devork.be>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: [PATCH] bindings/python-cffi: add matched property to message objects
Date: Sat, 01 Jan 2022 16:03:53 +0100 [thread overview]
Message-ID: <87ee5rlcpy.fsf@powell.devork.be> (raw)
In-Reply-To: <20220101144228.161473-1-david@tethera.net>
On Sat 01 Jan 2022 at 10:42 -0400, David Bremner wrote:
> Existing users of the legacy python bindings use
> message.get_flags(Message.FLAG.MATCH) to determine which messages in a
> thread matched. Since the bindings don't provide get_flags anymore,
> they should provide a property analogous to the existing "excluded"
> property.
> ---
> bindings/python-cffi/notmuch2/_message.py | 14 ++++++++++++++
> bindings/python-cffi/tests/test_message.py | 3 +++
> bindings/python-cffi/tests/test_thread.py | 7 +++++++
> 3 files changed, 24 insertions(+)
>
> diff --git a/bindings/python-cffi/notmuch2/_message.py b/bindings/python-cffi/notmuch2/_message.py
> index 2f232076..a460d8c1 100644
> --- a/bindings/python-cffi/notmuch2/_message.py
> +++ b/bindings/python-cffi/notmuch2/_message.py
> @@ -205,6 +205,20 @@ class Message(base.NotmuchObject):
> self._msg_p, capi.lib.NOTMUCH_MESSAGE_FLAG_EXCLUDED)
> return bool(ret)
>
> + @property
> + def matched(self):
> + """Indicates whether this message was matched by the query.
> +
> + When a thread is created from a search, some of the
> + messages may not match the original query. This property
> + is set to *True* for those that do match.
> +
> + :raises ObjectDestroyedError: if used after destroyed.
> + """
> + ret = capi.lib.notmuch_message_get_flag(
> + self._msg_p, capi.lib.NOTMUCH_MESSAGE_FLAG_MATCH)
> + return bool(ret)
> +
> @property
> def date(self):
> """The message date as an integer.
> diff --git a/bindings/python-cffi/tests/test_message.py b/bindings/python-cffi/tests/test_message.py
> index 532bf921..56701d05 100644
> --- a/bindings/python-cffi/tests/test_message.py
> +++ b/bindings/python-cffi/tests/test_message.py
> @@ -97,6 +97,9 @@ class TestMessage:
> def test_ghost_no(self, msg):
> assert not msg.ghost
>
> + def test_matched_no(self,msg):
> + assert not msg.matched
> +
> def test_date(self, msg):
> # XXX Someone seems to treat things as local time instead of
> # UTC or the other way around.
> diff --git a/bindings/python-cffi/tests/test_thread.py b/bindings/python-cffi/tests/test_thread.py
> index 1f44b35d..fbef73ac 100644
> --- a/bindings/python-cffi/tests/test_thread.py
> +++ b/bindings/python-cffi/tests/test_thread.py
> @@ -57,6 +57,13 @@ def test_iter(thread):
> def test_matched(thread):
> assert thread.matched == 1
>
> +def test_matched_iter(thread):
> + count = 0
> + msgs = list(iter(thread))
> + for msg in msgs:
> + if msg.matched:
> + count += 1
> + assert count == thread.matched
>
> def test_authors_type(thread):
> assert isinstance(thread.authors, notmuch2.BinString)
LGTM
next prev parent reply other threads:[~2022-01-01 15:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-01 14:42 [PATCH] bindings/python-cffi: add matched property to message objects David Bremner
2022-01-01 15:03 ` Floris Bruynooghe [this message]
2022-01-01 15:59 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ee5rlcpy.fsf@powell.devork.be \
--to=flub@devork.be \
--cc=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).