Commit eb99aa8c by Marius Gedminas

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'.
parent df1b41d3
...@@ -215,7 +215,7 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None): ...@@ -215,7 +215,7 @@ def to_bytes(obj, encoding='utf-8', errors='replace', nonstring=None):
return obj return obj
elif nonstring == 'simplerepr': elif nonstring == 'simplerepr':
try: try:
simple = binary_type(obj) simple = str(obj)
except UnicodeError: except UnicodeError:
try: try:
simple = obj.__str__() simple = obj.__str__()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment