1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Refs #28814 -- Imported from collections.abc to fix Python 3.7 deprecation warnings.

https://bugs.python.org/issue25988
This commit is contained in:
Raymond Hettinger 2018-02-05 08:42:47 -08:00 committed by Tim Graham
parent 8b21878357
commit aba9763b51
5 changed files with 11 additions and 10 deletions

View File

@ -1,4 +1,4 @@
import collections import collections.abc
import warnings import warnings
from math import ceil from math import ceil
@ -127,7 +127,7 @@ class Paginator:
QuerySetPaginator = Paginator # For backwards-compatibility. QuerySetPaginator = Paginator # For backwards-compatibility.
class Page(collections.Sequence): class Page(collections.abc.Sequence):
def __init__(self, object_list, number, paginator): def __init__(self, object_list, number, paginator):
self.object_list = object_list self.object_list = object_list

View File

@ -1,5 +1,5 @@
import builtins import builtins
import collections import collections.abc
import datetime import datetime
import decimal import decimal
import enum import enum
@ -341,7 +341,7 @@ def serializer_factory(value):
return FunctoolsPartialSerializer(value) return FunctoolsPartialSerializer(value)
if isinstance(value, (types.FunctionType, types.BuiltinFunctionType, types.MethodType)): if isinstance(value, (types.FunctionType, types.BuiltinFunctionType, types.MethodType)):
return FunctionTypeSerializer(value) return FunctionTypeSerializer(value)
if isinstance(value, collections.Iterable): if isinstance(value, collections.abc.Iterable):
return IterableSerializer(value) return IterableSerializer(value)
if isinstance(value, (COMPILED_REGEX_TYPE, RegexObject)): if isinstance(value, (COMPILED_REGEX_TYPE, RegexObject)):
return RegexSerializer(value) return RegexSerializer(value)

View File

@ -1,4 +1,4 @@
import collections import collections.abc
import copy import copy
import datetime import datetime
import decimal import decimal
@ -152,7 +152,7 @@ class Field(RegisterLookupMixin):
self.unique_for_date = unique_for_date self.unique_for_date = unique_for_date
self.unique_for_month = unique_for_month self.unique_for_month = unique_for_month
self.unique_for_year = unique_for_year self.unique_for_year = unique_for_year
if isinstance(choices, collections.Iterator): if isinstance(choices, collections.abc.Iterator):
choices = list(choices) choices = list(choices)
self.choices = choices or [] self.choices = choices or []
self.help_text = help_text self.help_text = help_text
@ -463,7 +463,7 @@ class Field(RegisterLookupMixin):
for name, default in possibles.items(): for name, default in possibles.items():
value = getattr(self, attr_overrides.get(name, name)) value = getattr(self, attr_overrides.get(name, name))
# Unroll anything iterable for choices into a concrete list # Unroll anything iterable for choices into a concrete list
if name == "choices" and isinstance(value, collections.Iterable): if name == "choices" and isinstance(value, collections.abc.Iterable):
value = list(value) value = list(value)
# Do correct kind of comparison # Do correct kind of comparison
if name in equals_comparison: if name in equals_comparison:

View File

@ -6,7 +6,8 @@ themselves do not have to (and could be backed by things other than SQL
databases). The abstraction barrier only works one way: this module has to know databases). The abstraction barrier only works one way: this module has to know
all about the internals of models in order to get the information it needs. all about the internals of models in order to get the information it needs.
""" """
from collections import Counter, Iterator, Mapping, OrderedDict, namedtuple from collections import Counter, OrderedDict, namedtuple
from collections.abc import Iterator, Mapping
from itertools import chain, count, product from itertools import chain, count, product
from string import ascii_uppercase from string import ascii_uppercase

View File

@ -1,4 +1,4 @@
import collections import collections.abc
from datetime import datetime from datetime import datetime
from math import ceil from math import ceil
from operator import attrgetter from operator import attrgetter
@ -99,7 +99,7 @@ class LookupTests(TestCase):
def test_iterator(self): def test_iterator(self):
# Each QuerySet gets iterator(), which is a generator that "lazily" # Each QuerySet gets iterator(), which is a generator that "lazily"
# returns results using database-level iteration. # returns results using database-level iteration.
self.assertIsInstance(Article.objects.iterator(), collections.Iterator) self.assertIsInstance(Article.objects.iterator(), collections.abc.Iterator)
self.assertQuerysetEqual( self.assertQuerysetEqual(
Article.objects.iterator(), Article.objects.iterator(),