Remove Python 3-specific conditional in dump_as_bytes

Now that we only support Python 3 we don't need logic to handle
Python 2.

Change-Id: I33747d25bc4c67ee13654ed132edf7413371c1dc
This commit is contained in:
Ben Nemec 2020-03-06 17:17:33 +00:00
parent ad356ea9c2
commit 909c17a779

View File

@ -214,11 +214,7 @@ def dump_as_bytes(obj, default=to_primitive, encoding='utf-8', **kwargs):
.. versionadded:: 1.10
"""
serialized = dumps(obj, default=default, **kwargs)
if isinstance(serialized, str):
# On Python 3, json.dumps() returns Unicode
serialized = serialized.encode(encoding)
return serialized
return dumps(obj, default=default, **kwargs).encode(encoding)
def dump(obj, fp, *args, **kwargs):