From b37aa284eb4aee17f5c6659e7533427ffcc5a2c8 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 30 May 2019 15:05:27 -0700 Subject: [PATCH] Remove unnecessary bytes() calls (#6626) --- rest_framework/renderers.py | 2 +- rest_framework/response.py | 2 +- rest_framework/test.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 2a4ae5905..3dc94ed2d 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -88,7 +88,7 @@ class JSONRenderer(BaseRenderer): Render `data` into JSON, returning a bytestring. """ if data is None: - return bytes() + return b'' renderer_context = renderer_context or {} indent = self.get_indent(accepted_media_type, renderer_context) diff --git a/rest_framework/response.py b/rest_framework/response.py index db7977770..495423734 100644 --- a/rest_framework/response.py +++ b/rest_framework/response.py @@ -73,7 +73,7 @@ class Response(SimpleTemplateResponse): 'renderer returned unicode, and did not specify ' 'a charset value.' ) - return bytes(ret.encode(charset)) + return ret.encode(charset) if not ret: del self['Content-Type'] diff --git a/rest_framework/test.py b/rest_framework/test.py index 852d4919e..ab16c2787 100644 --- a/rest_framework/test.py +++ b/rest_framework/test.py @@ -185,7 +185,7 @@ class APIRequestFactory(DjangoRequestFactory): # Coerce text to bytes if required. if isinstance(ret, str): - ret = bytes(ret.encode(renderer.charset)) + ret = ret.encode(renderer.charset) return ret, content_type