From 027e06437d596df1a53fd9f6efa89ea76fa29c5b Mon Sep 17 00:00:00 2001 From: Jerome Leclanche Date: Sun, 2 Sep 2018 09:10:23 +0300 Subject: [PATCH] Fix Python 3.7 DeprecationWarning (Python 3.8 compatibility) --- rest_framework/compat.py | 7 +++++++ rest_framework/serializers.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 28e1f1f59..2f4729214 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -10,6 +10,13 @@ from django.core import validators from django.utils import six from django.views.generic import View +try: + # Python 3 (required for 3.8+) + from collections.abc import Mapping # noqa +except ImportError: + # Python 2.7 + from collections import Mapping # noqa + try: from django.urls import ( # noqa URLPattern, diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index fb4b8d393..110ffbfa9 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -15,7 +15,7 @@ from __future__ import unicode_literals import copy import inspect import traceback -from collections import Mapping, OrderedDict +from collections import OrderedDict from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ValidationError as DjangoValidationError @@ -27,7 +27,7 @@ from django.utils import six, timezone from django.utils.functional import cached_property from django.utils.translation import ugettext_lazy as _ -from rest_framework.compat import postgres_fields, unicode_to_repr +from rest_framework.compat import Mapping, postgres_fields, unicode_to_repr from rest_framework.exceptions import ErrorDetail, ValidationError from rest_framework.fields import get_error_detail, set_value from rest_framework.settings import api_settings