From ed6340ee7619d7e8c3419ffacb973f7ca0c329d3 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Mon, 17 Sep 2018 01:39:59 -0700 Subject: [PATCH] Remove unnecessary use of compat shim six.binary_type (#6189) 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. --- rest_framework/compat.py | 2 +- rest_framework/fields.py | 2 +- rest_framework/utils/encoders.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 2f47292147..d6559d5f51 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -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 diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 3378de3685..61f3451b0a 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -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: diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py index fe8f76dd5b..d8f4aeb4eb 100644 --- a/rest_framework/utils/encoders.py +++ b/rest_framework/utils/encoders.py @@ -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'):