[notmuch] Unicode in Python bindings

Subject: [notmuch] Unicode in Python bindings

Date: Sun, 07 Jul 2013 09:00:16 +0200

To: Justus Winter

Cc:

From: Amadeusz Żołnowski


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
part-000.sig (application/pgp-signature)

Thread: