Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropping Python2 support #6590

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
26b6129
dropped python2.7 from tox and travis
auvipy Oct 24, 2018
cbafc5a
dropped python2.7 from readme
auvipy Oct 25, 2018
244d233
dropped python 2.7 compat code
auvipy Oct 25, 2018
0aa2958
Merge branch 'py2drop' of https://github.com/auvipy/django-rest-frame…
auvipy Oct 25, 2018
7e87449
dropped python 2.7 compat code from tests
auvipy Oct 25, 2018
5a6747d
dropped python 2.7 compat codes
auvipy Oct 25, 2018
d00211b
dropped python 2.7 compat codes from tests
auvipy Oct 25, 2018
87e603e
removed old style object inheritance and super() call from authtocken…
auvipy Oct 25, 2018
b1bbbc8
removed old style object inheritance, super() call and python2compat …
auvipy Oct 25, 2018
8e52e7f
fixed isort issue
auvipy Oct 25, 2018
47036c0
removed old style object inheritance and super() call
auvipy Oct 25, 2018
15a3952
kept a super() call explicit due to https://stackoverflow.com/questio…
auvipy Oct 25, 2018
a63a68c
kept a super() call explicit due to https://stackoverflow.com/questio…
auvipy Oct 25, 2018
7e0d416
fixed merge conflicts
auvipy Mar 4, 2019
b1b56ee
fixed isort failures
auvipy Mar 6, 2019
1b817d9
remove more python2 compat codes from tests
auvipy Mar 10, 2019
bcf64e5
remove more python2 compat codes
auvipy Mar 10, 2019
ebb1a23
Merge branch 'master' of https://github.com/encode/django-rest-framew…
auvipy Mar 20, 2019
30dc38b
Merge branch 'master' of https://github.com/encode/django-rest-framew…
auvipy Mar 31, 2019
f734344
isort fix
auvipy Mar 31, 2019
c2c11a5
remove six codes from compat
auvipy Mar 31, 2019
74dfa54
Removed repeated models in tests
Apr 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ dist: xenial
matrix:
fast_finish: true
include:
- { python: "2.7", env: DJANGO=1.11 }

- { python: "3.4", env: DJANGO=1.11 }
- { python: "3.4", env: DJANGO=2.0 }
Expand All @@ -25,9 +24,10 @@ matrix:
- { python: "3.7", env: DJANGO=2.2 }
- { python: "3.7", env: DJANGO=master }

- { python: "3.7", env: TOXENV=base }
- { python: "2.7", env: TOXENV=lint }
- { python: "2.7", env: TOXENV=docs }
- { python: "3.6", env: TOXENV=base }
- { python: "3.6", env: TOXENV=lint }
- { python: "3.6", env: TOXENV=docs }


- python: "3.7"
env: TOXENV=dist
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ There is a live example API for testing purposes, [available here][sandbox].

# Requirements

* Python (2.7, 3.4, 3.5, 3.6, 3.7)
* Python (3.4, 3.5, 3.6, 3.7)
* Django (1.11, 2.0, 2.1, 2.2)


We **highly recommend** and only officially support the latest patch release of
each Python and Django series.

Expand Down
3 changes: 1 addition & 2 deletions rest_framework/authentication.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Provides various authentication policies.
"""
from __future__ import unicode_literals

import base64
import binascii
Expand Down Expand Up @@ -33,7 +32,7 @@ def _reject(self, request, reason):
return reason


class BaseAuthentication(object):
class BaseAuthentication:
"""
All authentication classes should extend BaseAuthentication.
"""
Expand Down
3 changes: 0 additions & 3 deletions rest_framework/authtoken/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models

Expand Down
4 changes: 1 addition & 3 deletions rest_framework/authtoken/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

from django.conf import settings
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _


@python_2_unicode_compatible
class Token(models.Model):
"""
The default authorization token model.
Expand All @@ -32,7 +30,7 @@ class Meta:
def save(self, *args, **kwargs):
if not self.key:
self.key = self.generate_key()
return super(Token, self).save(*args, **kwargs)
return super().save(*args, **kwargs)

def generate_key(self):
return binascii.hexlify(os.urandom(20)).decode()
Expand Down
38 changes: 10 additions & 28 deletions rest_framework/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@
versions of Django/Python, and compatibility wrappers around optional packages.
"""

from __future__ import unicode_literals

import sys
from collections.abc import Mapping, MutableMapping # noqa

from django.conf import settings
from django.core import validators
from django.utils import six
from django.views.generic import View

try:
# Python 3
from collections.abc import Mapping, MutableMapping # noqa
except ImportError:
# Python 2.7
from collections import Mapping, MutableMapping # noqa

try:
from django.urls import ( # noqa
URLPattern,
Expand Down Expand Up @@ -92,17 +83,15 @@ def make_url_resolver(regex, urlpatterns):
def unicode_repr(instance):
# Get the repr of an instance, but ensure it is a unicode string
# on both python 3 (already the case) and 2 (not the case).
if six.PY2:
return repr(instance).decode('utf-8')

return repr(instance)


def unicode_to_repr(value):
# Coerce a unicode string to the correct repr return type, depending on
# the Python version. We wrap all our `__repr__` implementations with
# this and then use unicode throughout internally.
if six.PY2:
return value.encode('utf-8')

return value


Expand Down Expand Up @@ -168,10 +157,7 @@ def is_guardian_installed():
"""
django-guardian is optional and only imported if in INSTALLED_APPS.
"""
if six.PY2:
# Guardian 1.5.0, for Django 2.2 is NOT compatible with Python 2.7.
# Remove when dropping PY2.
return False

return 'guardian' in settings.INSTALLED_APPS


Expand Down Expand Up @@ -284,17 +270,13 @@ def md_filter_add_syntax_highlight(md):

# `separators` argument to `json.dumps()` differs between 2.x and 3.x
# See: https://bugs.python.org/issue22767
if six.PY3:
SHORT_SEPARATORS = (',', ':')
LONG_SEPARATORS = (', ', ': ')
INDENT_SEPARATORS = (',', ': ')
else:
SHORT_SEPARATORS = (b',', b':')
LONG_SEPARATORS = (b', ', b': ')
INDENT_SEPARATORS = (b',', b': ')

SHORT_SEPARATORS = (',', ':')
LONG_SEPARATORS = (', ', ': ')
INDENT_SEPARATORS = (',', ': ')


class CustomValidatorMessage(object):
class CustomValidatorMessage:
"""
We need to avoid evaluation of `lazy` translated `message` in `django.core.validators.BaseValidator.__init__`.
https://github.com/django/django/blob/75ed5900321d170debef4ac452b8b3cf8a1c2384/django/core/validators.py#L297
Expand All @@ -304,7 +286,7 @@ class CustomValidatorMessage(object):

def __init__(self, *args, **kwargs):
self.message = kwargs.pop('message', self.message)
super(CustomValidatorMessage, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class MinValueValidator(CustomValidatorMessage, validators.MinValueValidator):
Expand Down
1 change: 0 additions & 1 deletion rest_framework/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
based views, as well as the `@detail_route` and `@list_route` decorators, which are
used to annotate methods on viewsets that should be included by routers.
"""
from __future__ import unicode_literals

import types
import warnings
Expand Down
11 changes: 5 additions & 6 deletions rest_framework/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
In addition Django's built in 403 and 404 exceptions are handled.
(`django.http.Http404` and `django.core.exceptions.PermissionDenied`)
"""
from __future__ import unicode_literals

import math

Expand Down Expand Up @@ -76,7 +75,7 @@ def __new__(cls, string, code=None):
return self

def __eq__(self, other):
r = super(ErrorDetail, self).__eq__(other)
r = super().__eq__(other)
try:
return r and self.code == other.code
except AttributeError:
Expand Down Expand Up @@ -196,7 +195,7 @@ class MethodNotAllowed(APIException):
def __init__(self, method, detail=None, code=None):
if detail is None:
detail = force_text(self.default_detail).format(method=method)
super(MethodNotAllowed, self).__init__(detail, code)
super().__init__(detail, code)


class NotAcceptable(APIException):
Expand All @@ -206,7 +205,7 @@ class NotAcceptable(APIException):

def __init__(self, detail=None, code=None, available_renderers=None):
self.available_renderers = available_renderers
super(NotAcceptable, self).__init__(detail, code)
super().__init__(detail, code)


class UnsupportedMediaType(APIException):
Expand All @@ -217,7 +216,7 @@ class UnsupportedMediaType(APIException):
def __init__(self, media_type, detail=None, code=None):
if detail is None:
detail = force_text(self.default_detail).format(media_type=media_type)
super(UnsupportedMediaType, self).__init__(detail, code)
super().__init__(detail, code)


class Throttled(APIException):
Expand All @@ -238,7 +237,7 @@ def __init__(self, wait=None, detail=None, code=None):
self.extra_detail_plural.format(wait=wait),
wait))))
self.wait = wait
super(Throttled, self).__init__(detail, code)
super().__init__(detail, code)


def server_error(request, *args, **kwargs):
Expand Down
Loading