Message 25840 - Python tracker (original) (raw)

The example below shows that list(f) swallows the KeyboardInterrupt.

It swallows any other exception too, such as MemoryError or application-specific ConflictErrors.

I think the "get the length of the object" optimisation should catch only AttributeError and TypeError.

class F(object): ... def iter(self): ... yield 23 ... def len(self): ... print "len called. raising Keyboard Interrupt." ... raise KeyboardInterrupt ... f = F() list(f) len called. raising Keyboard Interrupt. [23]