mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-30 18:09:59 +03:00
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.
This commit is contained in:
parent
9d001cd84c
commit
339dfab5f5
|
@ -1,6 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import collections
|
||||
import copy
|
||||
import datetime
|
||||
import decimal
|
||||
|
@ -33,7 +32,7 @@ from pytz.exceptions import InvalidTimeError
|
|||
|
||||
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 @@ class ListField(Field):
|
|||
"""
|
||||
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')
|
||||
|
|
Loading…
Reference in New Issue
Block a user