Possible Duplicate:
Python builtin “all” with generators
I've come across the following reproducible behaviour in IPython:
def test(lst):
for val in (v is not None for v in lst):
print val
print all(v is not None for v in lst)
print
print [v is not None for v in lst]
print all([v is not None for v in lst])
print
print
for val in (v is None for v in lst):
print val
print all(v is None for v in lst)
print
print [v is None for v in lst]
print all([v is None for v in lst])
>>> test([1])
True
True
[True]
True
False
True
[False]
False
The error originally appeared in the midst of a much larger algorithm, but it reduces to the above test case.
Now this output is clearly wrong, but I've got no idea what's going on. If I repeat in the standard python shell, it gives the expected output.
Additional Notes
The third set of print statements show the error:
all(v is None for v in [1])
should return True, not False.
IPython is running with a lot of objects loaded (about 1.5GB worth, most below one parent object). If I close everything and restart, the error disappears, but it reappears if reload my data.
My thought is that there must be some memory corruption going on, but I'm stumped as to what it could be. Any ideas?