unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: Floris Bruynooghe <flub@devork.be>,
	David Bremner <david@tethera.net>,
	notmuch@notmuchmail.org
Subject: 
Date: Wed, 16 Feb 2022 22:08:33 -0400	[thread overview]
Message-ID: <20220217020835.180940-1-david@tethera.net> (raw)
In-Reply-To: <8735kipm9j.fsf@powell.devork.be>

Floris wrote: 
> FWIW having spaces between the function name and parentheses is rather
>uncommon for python style.  Though of course complaining about style
>without using an auto-formatter is pretty meh these days :)
>

Yeah fair enough, it's the default in the C code, but we pretty
clearly have different styles going on in different languages.

>> +            val_p = capi.lib.notmuch_config_pairs_value (super()._iter_p)
>> +            key_p = capi.lib.notmuch_config_pairs_key (super()._iter_p)
>> +            key = base.BinString.from_cffi(key_p)
>
>does key_p need a NULL check first or can it never be NULL?

I think it can never be NULL, but if it is, better to raise an exception I think.

>>      def test_iter(self, db):
>> -        assert list(db.config) == []
>> -        db.config['spam'] = 'ham'
>> -        db.config['eggs'] = 'bacon'
>> -        assert set(db.config) == {'spam', 'eggs'}
>> -        assert set(db.config.keys()) == {'spam', 'eggs'}
>> -        assert set(db.config.values()) == {'ham', 'bacon'}
>> -        assert set(db.config.items()) == {('spam', 'ham'), ('eggs', 'bacon')}
>> +        import re
>> +        prefix = re.compile(r"^TEST[.]")
>> +        assert [ x for x in list(db.config) if prefix.match(x) ] == []
>
>`x.startswith('TEST.')` is probably lighter weight here, maybe easier to
>read too that's subjective i guess
>
>You can even try something like this to further make it more readable:
>
>has_prefix = lambda x: x.startswith('TEST.')

I did variation on this, defining an inner function instead of using a lambda.

>
>> +        db.config['TEST.spam'] = 'TEST.ham'
>> +        db.config['TEST.eggs'] = 'TEST.bacon'
>> +        assert { x for x in set(db.config) if prefix.match(x) } == {'TEST.spam', 'TEST.eggs'}
>> +        assert { x for x in set(db.config.keys()) if prefix.match (x) } == {'TEST.spam', 'TEST.eggs'}
>
>I'm not sure why you need to wrap `db.config.keys()` in `set()`?  This
>explicitly creates a set out of things before turning it back into an
>interator while you're fine with the original iterator I think?

Good question. That seems to apply to list(db.config) above also? 

  reply	other threads:[~2022-02-17  2:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-11 13:04 use new config API in python-cffi config iterator David Bremner
2022-02-11 13:04 ` [PATCH 1/2] test: known broken test for list(db.config) in python-cffi bindings David Bremner
2022-02-11 13:04 ` [PATCH 2/2] python-cffi: use config_pairs API in ConfigIterator David Bremner
2022-02-16 20:52   ` Floris Bruynooghe
2022-02-17  2:08     ` David Bremner [this message]
2022-02-17  2:08       ` [PATCH v2 1/2] test: known broken test for list(db.config) in python-cffi bindings David Bremner
2022-02-17  2:08       ` [PATCH v2 2/2] python-cffi: use config_pairs API in ConfigIterator David Bremner
2022-02-17 21:30         ` Floris Bruynooghe
2022-02-18  0:27           ` 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=20220217020835.180940-1-david@tethera.net \
    --to=david@tethera.net \
    --cc=flub@devork.be \
    --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).