Skip to content

Commit

Permalink
Remove unnecessary use of compat shim six.binary_type (encode#6189)
Browse files Browse the repository at this point in the history
The type bytes is available on all supported Pythons. On Python 2.7, it
is an alias for str, same as six.binary_type. Makes the code more
forward compatible with Python 3.
  • Loading branch information
jdufresne authored and carltongibson committed Sep 17, 2018
1 parent fc6cbb5 commit ed6340e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def unicode_to_repr(value):

def unicode_http_header(value):
# Coerce HTTP header value to unicode.
if isinstance(value, six.binary_type):
if isinstance(value, bytes):
return value.decode('iso-8859-1')
return value

Expand Down
2 changes: 1 addition & 1 deletion rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1780,7 +1780,7 @@ def __new__(self, value):
def to_internal_value(self, data):
try:
if self.binary or getattr(data, 'is_json_string', False):
if isinstance(data, six.binary_type):
if isinstance(data, bytes):
data = data.decode('utf-8')
return json.loads(data)
else:
Expand Down
2 changes: 1 addition & 1 deletion rest_framework/utils/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def default(self, obj):
return six.text_type(obj)
elif isinstance(obj, QuerySet):
return tuple(obj)
elif isinstance(obj, six.binary_type):
elif isinstance(obj, bytes):
# Best-effort for binary blobs. See #4187.
return obj.decode('utf-8')
elif hasattr(obj, 'tolist'):
Expand Down

0 comments on commit ed6340e

Please sign in to comment.