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

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

Date: Wed, 04 Jan 2012 20:07:11 +0200

To: Sebastian Spaeth, Justus Winter, notmuch@notmuchmail.org

Cc:

From: Tomi Ollila


On Mon, 02 Jan 2012 16:15:58 +0100, Sebastian Spaeth <Sebastian@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

Thread: