Fix bug in jsonbytes.

This commit is contained in:
Itamar Turner-Trauring 2021-08-27 10:14:39 -04:00
parent bb48974fd8
commit d5b48e65c7
2 changed files with 7 additions and 1 deletions

View File

@ -558,6 +558,12 @@ class JSONBytes(unittest.TestCase):
expected
)
def test_dumps_bytes_unicode_separators(self):
"""Unicode separators don't prevent the result from being bytes."""
result = jsonbytes.dumps_bytes([1, 2], separators=(u',', u':'))
self.assertIsInstance(result, bytes)
self.assertEqual(result, b"[1,2]")
class FakeGetVersion(object):
"""Emulate an object with a get_version."""

View File

@ -109,7 +109,7 @@ def dumps_bytes(obj, *args, **kwargs):
human consumption.
"""
result = dumps(obj, *args, **kwargs)
if PY3:
if PY3 or isinstance(result, str):
result = result.encode("utf-8")
return result