Fix to_bytes(None) on Python 3

You cannot call bytes(obj) to get a simple representation of obj on
Python 3!  E.g. bytes(42) returns a byte string with 42 NUL characters
instead of b'42'.
This commit is contained in:
Marius Gedminas 2015-08-27 09:38:12 +03:00
parent df1b41d3d3
commit eb99aa8c68

View file

@ -215,7 +215,7 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None):
return obj
elif nonstring == 'simplerepr':
try:
simple = binary_type(obj)
simple = str(obj)
except UnicodeError:
try:
simple = obj.__str__()