Replaced 'next' testing by collections.Iterator testing.
The new construct is also Python 3 compatible (where 'next' has been renamed to '__next__').
This commit is contained in:
parent
d5c7f9efc3
commit
df7a65ac4b
|
@ -1,3 +1,4 @@
|
||||||
|
import collections
|
||||||
import copy
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
|
@ -436,7 +437,7 @@ class Field(object):
|
||||||
return bound_field_class(self, fieldmapping, original)
|
return bound_field_class(self, fieldmapping, original)
|
||||||
|
|
||||||
def _get_choices(self):
|
def _get_choices(self):
|
||||||
if hasattr(self._choices, 'next'):
|
if isinstance(self._choices, collections.Iterator):
|
||||||
choices, self._choices = tee(self._choices)
|
choices, self._choices = tee(self._choices)
|
||||||
return choices
|
return choices
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -4,6 +4,7 @@ Code to manage the creation and SQL rendering of 'where' constraints.
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import collections
|
||||||
import datetime
|
import datetime
|
||||||
from itertools import repeat
|
from itertools import repeat
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ class WhereNode(tree.Node):
|
||||||
return
|
return
|
||||||
|
|
||||||
obj, lookup_type, value = data
|
obj, lookup_type, value = data
|
||||||
if hasattr(value, '__iter__') and hasattr(value, 'next'):
|
if isinstance(value, collections.Iterator):
|
||||||
# Consume any generators immediately, so that we can determine
|
# Consume any generators immediately, so that we can determine
|
||||||
# emptiness and transform any non-empty values correctly.
|
# emptiness and transform any non-empty values correctly.
|
||||||
value = list(value)
|
value = list(value)
|
||||||
|
|
Loading…
Reference in New Issue