[PATCH 6/7] py3k: Add and use a mixin class that implements __str__

Tomi Ollila tomi.ollila at iki.fi
Wed Dec 14 04:26:38 PST 2011


On Wed, 14 Dec 2011 11:58:24 +0100, Justus Winter <4winter at informatik.uni-hamburg.de> wrote:
> ---
[ ... snip ... ]

>  
> -class Filenames(object):
> +class Filenames(Python3StringMixIn):
>      """Represents a list of filenames as returned by notmuch
>  
>      This object contains the Filenames iterator. The main function is
> @@ -98,9 +98,6 @@ class Filenames(object):
>  
>          self._files = None
>  
> -    def __str__(self):
> -        return unicode(self).encode('utf-8')
> -
>      def __unicode__(self):
>          """Represent Filenames() as newline-separated list of full paths
>  
> diff --git a/bindings/python/notmuch/globals.py b/bindings/python/notmuch/globals.py
> index c52790c..2111b86 100644
> --- a/bindings/python/notmuch/globals.py
> +++ b/bindings/python/notmuch/globals.py
> @@ -28,6 +28,16 @@ except:
>      raise ImportError("Could not find shared 'notmuch' library.")
>  
>  
> +if sys.version_info[0] == 2:
> +    class Python3StringMixIn(object):
> +        def __str__(self):
> +            return unicode(self).encode('utf-8')
> +else:
> +    class Python3StringMixIn(object):
> +        def __str__(self):
> +            return self.__unicode__()
> +
> +

[ ... snip ... ]

> -class Threads(object):
> +class Threads(Python3StringMixIn):
>      """Represents a list of notmuch threads
>  
>      This object provides an iterator over a list of notmuch threads
> @@ -393,7 +393,7 @@ class Thread(object):
>          return Tags(tags_p, self)
>  
>      def __str__(self):
> -        return unicode(self).encode('utf-8')
> +        return self.__unicode__().encode('utf-8')
>  
>      def __unicode__(self):
>          frm = "thread:%s %12s [%d/%d] %s; %s (%s)"

Is this class special case ? in all other classes
the __str__() function has been removed (using inherited
function) ?

> -- 
> 1.7.7.3

Otherwise LGTM -- pretty simple and effective (all 7 patches).

Tomi



More information about the notmuch mailing list