[PATCH 5/7] py3k: the basestring and unicode types are removed in python 3

Tomi Ollila tomi.ollila at iki.fi
Wed Jan 4 10:07:11 PST 2012


On Mon, 02 Jan 2012 16:15:58 +0100, Sebastian Spaeth <Sebastian at SSpaeth.de> wrote:
> Happy new year. Pushed patches 1-4 of this series so far. Looking fine,
> but ugh, the below seems like a rather ugly hack in a function that is
> probably called quite often.
> 
> Isn't there a more pretty variant avoiding these sys.version_info checks
> all over the place?
> 
> > @@ -200,9 +201,9 @@ def _str(value):
> >  
> >      C++ code expects strings to be well formatted and
> >      unicode strings to have no null bytes."""
> > -    if not isinstance(value, basestring):
> > +    if not isinstance(value, basestring if sys.version_info[0] == 2 else str):
> >          raise TypeError("Expected str or unicode, got %s" % str(type(value)))
> > -    if isinstance(value, unicode):
> > +    if sys.version_info[0] == 3 or isinstance(value, unicode):
> >          return value.encode('UTF-8')
> >      return value

Does the Python3StringMixIn stuff in later patches already handle this
patch -- and making this obsolete ?

Tomi


More information about the notmuch mailing list