Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Replaced 'next' testing by collections.Iterator testing.

The new construct is also Python 3 compatible (where 'next' has
been renamed to '__next__').
  • Loading branch information...
commit df7a65ac4ba36dd155e80b8bcfe607390976ad47 1 parent d5c7f9e
Claude Paroz authored May 22, 2012
3  django/db/models/fields/__init__.py
... ...
@@ -1,3 +1,4 @@
  1
+import collections
1 2
 import copy
2 3
 import datetime
3 4
 import decimal
@@ -436,7 +437,7 @@ def bind(self, fieldmapping, original, bound_field_class):
436 437
         return bound_field_class(self, fieldmapping, original)
437 438
 
438 439
     def _get_choices(self):
439  
-        if hasattr(self._choices, 'next'):
  440
+        if isinstance(self._choices, collections.Iterator):
440 441
             choices, self._choices = tee(self._choices)
441 442
             return choices
442 443
         else:
3  django/db/models/sql/where.py
@@ -4,6 +4,7 @@
4 4
 
5 5
 from __future__ import absolute_import
6 6
 
  7
+import collections
7 8
 import datetime
8 9
 from itertools import repeat
9 10
 
@@ -49,7 +50,7 @@ def add(self, data, connector):
49 50
             return
50 51
 
51 52
         obj, lookup_type, value = data
52  
-        if hasattr(value, '__iter__') and hasattr(value, 'next'):
  53
+        if isinstance(value, collections.Iterator):
53 54
             # Consume any generators immediately, so that we can determine
54 55
             # emptiness and transform any non-empty values correctly.
55 56
             value = list(value)

0 notes on commit df7a65a

Please sign in to comment.
Something went wrong with that request. Please try again.