Fixed #20094 - Be more careful when checking for Iterator. #933

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

@mjtamlyn
Member

Python 2.6 has some different behaviour when checking isinstance(foo, collections.Iterator).

cc @claudep

@akaariai akaariai and 1 other commented on an outdated diff Mar 20, 2013
django/utils/itercompat.py
@@ -17,6 +19,17 @@ def is_iterable(x):
else:
return True
+def is_iterator(x):
+ """An implementation independent way of checking for iterators
+
+ Python 2.6 has a different implementation of collections.Iterable which
+ accepts anything with a `next` method. 2.7+ requires and `__iter__` method
+ as well.
+ """
+ if sys.version_info <= (2.7):
@akaariai
akaariai Mar 20, 2013 Django member

This code isn't correct. (2, 7) is the check you want, and then with >= if I am not mistaken.

@mjtamlyn
mjtamlyn Mar 20, 2013 Django member

Oops, muppet.

@charettes charettes and 1 other commented on an outdated diff Mar 20, 2013
django/utils/itercompat.py
@@ -17,6 +19,17 @@ def is_iterable(x):
else:
return True
+def is_iterator(x):
+ """An implementation independent way of checking for iterators
+
+ Python 2.6 has a different implementation of collections.Iterable which
@charettes
charettes Mar 20, 2013 Django member

Looking at collections source code I think you mean collections.Iterator here.

@mjtamlyn
mjtamlyn Mar 20, 2013 Django member

Yup!

@mjtamlyn mjtamlyn Fixed #20094 - Be more careful when checking for Iterator.
Python 2.6 has some different behaviour when checking
isinstance(foo, collections.Iterator).
618949e
@timgraham
Member

Looks like this was merged in 829dc3c

@timgraham timgraham closed this Mar 22, 2013
@mjtamlyn mjtamlyn deleted the mjtamlyn:collections.Iterable branch Mar 23, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment