- No longer expects include_columns in table reflection to be
lower case.
-
+
+- misc
+ - util.flatten_iterator() func doesn't interpret strings with
+ __iter__() methods as iterators, such as in pypy [ticket:1077].
+
0.5.0rc2
========
- orm
def flatten_iterator(x):
"""Given an iterator of which further sub-elements may also be
iterators, flatten the sub-elements into a single iterator.
- """
+ """
for elem in x:
- if hasattr(elem, '__iter__'):
+ if not isinstance(elem, basestring) and hasattr(elem, '__iter__'):
for y in flatten_iterator(elem):
yield y
else:
class ImmutableSubclass(str):
pass
+class FlattenIteratorTest(TestBase):
+ def test_flatten(self):
+ assert list(util.flatten_iterator([[1,2,3], [4,5,6], 7, 8])) == [1,2,3,4,5,6,7,8]
+
+ def test_str_with_iter(self):
+ """ensure that a str object with an __iter__ method (like in PyPy) is not interpreted
+ as an iterable.
+
+ """
+ class IterString(str):
+ def __iter__(self):
+ return iter(self + "")
+
+ assert list(util.flatten_iterator([IterString("asdf"), [IterString("x"), IterString("y")]])) == ["asdf", "x", "y"]
+
class HashOverride(object):
def __init__(self, value=None):
self.value = value