From 339dfab5f5070bd1e3ba54ea63f62f985816689b Mon Sep 17 00:00:00 2001 From: Charlie Hornsby Date: Sat, 20 Oct 2018 18:28:52 +0300 Subject: [PATCH 1/2] Use compat version of collections.abc.Mapping Since the Mapping class will no longer be available to import directly from the collections module in Python 3.8, we should use the compatibility helper introduced in #6154 in the fields module. --- rest_framework/fields.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 70c210c162..b451f8fefa 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -1,6 +1,5 @@ from __future__ import unicode_literals -import collections import copy import datetime import decimal @@ -33,7 +32,7 @@ from rest_framework import ISO_8601 from rest_framework.compat import ( - MaxLengthValidator, MaxValueValidator, MinLengthValidator, + Mapping, MaxLengthValidator, MaxValueValidator, MinLengthValidator, MinValueValidator, ProhibitNullCharactersValidator, unicode_repr, unicode_to_repr ) @@ -96,7 +95,7 @@ def get_attribute(instance, attrs): """ for attr in attrs: try: - if isinstance(instance, collections.Mapping): + if isinstance(instance, Mapping): instance = instance[attr] else: instance = getattr(instance, attr) @@ -1661,7 +1660,7 @@ def to_internal_value(self, data): """ if html.is_html_input(data): data = html.parse_html_list(data, default=[]) - if isinstance(data, type('')) or isinstance(data, collections.Mapping) or not hasattr(data, '__iter__'): + if isinstance(data, type('')) or isinstance(data, Mapping) or not hasattr(data, '__iter__'): self.fail('not_a_list', input_type=type(data).__name__) if not self.allow_empty and len(data) == 0: self.fail('empty') From 319071d3192fe09262d118a1c6e5977107eacb3a Mon Sep 17 00:00:00 2001 From: Charlie Hornsby Date: Sat, 20 Oct 2018 18:29:59 +0300 Subject: [PATCH 2/2] Alias and use compat version of collections.abc.MutableMapping Since the MutableMapping class will no longer be available to import directly from the collections module in Python 3.8, we should create an alias for it in the compat module and use that instead. --- rest_framework/compat.py | 4 ++-- rest_framework/utils/serializer_helpers.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 1d34828bdc..061e7a4e9c 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -12,10 +12,10 @@ try: # Python 3 - from collections.abc import Mapping # noqa + from collections.abc import Mapping, MutableMapping # noqa except ImportError: # Python 2.7 - from collections import Mapping # noqa + from collections import Mapping, MutableMapping # noqa try: # Python 3 diff --git a/rest_framework/utils/serializer_helpers.py b/rest_framework/utils/serializer_helpers.py index 6b662a66ca..c24e51d091 100644 --- a/rest_framework/utils/serializer_helpers.py +++ b/rest_framework/utils/serializer_helpers.py @@ -1,11 +1,10 @@ from __future__ import unicode_literals -import collections from collections import OrderedDict from django.utils.encoding import force_text -from rest_framework.compat import unicode_to_repr +from rest_framework.compat import MutableMapping, unicode_to_repr from rest_framework.utils import json @@ -130,7 +129,7 @@ def as_form_field(self): return self.__class__(self._field, values, self.errors, self._prefix) -class BindingDict(collections.MutableMapping): +class BindingDict(MutableMapping): """ This dict-like object is used to store fields on a serializer. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy