From c2ec2ad8fbbd684d2820dbdc1f1198a8cd7f64e0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sun, 30 Aug 2015 11:48:06 +0100 Subject: [PATCH] tests: Add test where __getitem__ raises IndexError to stop iteration. --- tests/basics/getitem.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/basics/getitem.py b/tests/basics/getitem.py index 3029f83035..4944641d15 100644 --- a/tests/basics/getitem.py +++ b/tests/basics/getitem.py @@ -21,6 +21,12 @@ try: except StopIteration: pass +# this class raises an IndexError to stop the iteration +class A: + def __getitem__(self, i): + raise IndexError +print(list(A())) + # this class raises a non-StopIteration exception on iteration class A: def __getitem__(self, i):