Skip to content

Commit

Permalink
Used early return as before
Browse files Browse the repository at this point in the history
  • Loading branch information
sliverc committed Jan 8, 2025
1 parent c05926b commit 1b5a84a
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions rest_framework/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def _encode_data(self, data, format=None, content_type=None):
"""
Encode the data returning a two tuple of (bytes, content_type)
"""
if data is None:
return (b'', content_type)

assert format is None or content_type is None, (
'You may not set both `format` and `content_type`.'
Expand All @@ -161,9 +163,6 @@ def _encode_data(self, data, format=None, content_type=None):
except AttributeError:
pass

if data is None:
data = ''

# Content type specified explicitly, treat data as a raw bytestring
ret = force_bytes(data, settings.DEFAULT_CHARSET)

Expand All @@ -181,6 +180,7 @@ def _encode_data(self, data, format=None, content_type=None):

# Use format and render the data into a bytestring
renderer = self.renderer_classes[format]()
ret = renderer.render(data)

# Determine the content-type header from the renderer
content_type = renderer.media_type
Expand All @@ -189,14 +189,9 @@ def _encode_data(self, data, format=None, content_type=None):
content_type, renderer.charset
)

if data is None:
ret = ''
else:
ret = renderer.render(data)

# Coerce text to bytes if required.
if isinstance(ret, str) and renderer.charset:
ret = ret.encode(renderer.charset)
# Coerce text to bytes if required.
if isinstance(ret, str):
ret = ret.encode(renderer.charset)

return ret, content_type

Expand Down

0 comments on commit 1b5a84a

Please sign in to comment.