[notmuch] Unicode in Python bindings

Amadeusz Żołnowski aidecoe at aidecoe.name
Sun Jul 7 00:00:16 PDT 2013


Hello,

I have come across a problem with Unicode [1] in afew mail filter which
uses Notmuch Python bindings and it has eventually bringed us to
confusion about Unicode handling in Python bindings.

Shouldn't __unicode__() methods return value of type unicode?  Let's
take an example of __unicode__() method from Message class:

    def __unicode__(self):
        format = "%s (%s) (%s)"
        return format % (self.get_header('from'),
                         self.get_tags(),                
                         date.fromtimestamp(self.get_date()),
                        )

format is of type str, not unicode and method is eventually going to
return str, while the user of the API is expecting unicode type.

I haven't programmed in Python 3, yet - only in Python 2, so maybe I am
missing something.  When I was writing a big project in Python 2, I have
eventually decided to use u'' literals everywhere and decode any str to
unicode ASAP - and this solved all issues wrt encodings.  I guess that
mixing Python 2 and 3 gets even more problematic.

Could you review (and fix if it is needed) Python bindings in context of
unicode handling, please?


[1] https://github.com/teythoon/afew/issues/36


Regards,

-- 
Amadeusz Żołnowski
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20130707/d06feced/attachment.pgp>


More information about the notmuch mailing list