The name seems confusing to me: it's called bytes_type but its main purpose is to exclude bytes on Python 2. Otherwise you'd just write isinstance(value, (bytes, six.memoryview)).
If indeed you want "bytes or bytes-like on Py 3, bytes-like but not bytes on Py 2" then your if clause is perfectly clear and reasonable as is. (Remember that bytes is an alias for str on Py 2.) FYI django.utils.six.memoryview is a lazy hack to get the test suite to pass on Python 2 and 3, I wouldn't be surprised if it's used inappropriately :-/ -- Aymeric. > Le 28 mai 2014 à 17:38, Shai Berger <[email protected]> a écrit : > > Hi all, > > While solving #22715[1], I found myself writing these lines: > > elif (isinstance(value, six.memoryview) or > six.PY3 and isinstance(value, bytes)): > .... > > six.memoryview -- django.utils.six.memoryview, to be accurate, there's no > memoryview in the original six library -- is defined to be `memoryview` on > python3, and `buffer` on python2. But having written this code, I thought the > distinction might have more general value, and so we should maybe add a > "bytes_types" -- similar to six.string_types -- which would be defined as > `buffer` on python2, but `(memoryview, bytes)` on python3. The above would > change to > > elif isinstance(value, six.bytes_types): > .... > > which is obviously nicer. > > The question to you is, is it just me? Do you think "bytes_types" can be > useful? > > Thanks, > Shai. > > [1] https://code.djangoproject.com/ticket/22715 > > -- > You received this message because you are subscribed to the Google Groups > "Django developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/django-developers. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/201405281838.15889.shai%40platonix.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Django developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/6E968B1F-62E7-49A8-BDDC-181B18E8F1CE%40polytechnique.org. For more options, visit https://groups.google.com/d/optout.
