[PATCH 5/7] py3k: the basestring and unicode types are removed in python 3
Sebastian Spaeth
Sebastian at SSpaeth.de
Mon Jan 2 07:15:58 PST 2012
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20120102/48d967f0/attachment.pgp>
More information about the notmuch
mailing list