[IronPython] Iteration via __getitem__ doesn't work in the Visual Studio debugging environment

Dino Viehland dinov at microsoft.com
Thu Sep 9 02:47:13 CEST 2010


Tony wrote:
> I have this program:
> 
> class A(object):
>     def __init__(self):
>         self.data = range(5)
>     def __getitem__(self, item):
>         return self.data[item]
> a = A()
> for v in a:
>     print v
> 
> i.e. there's a class that gets iteration through the __getitem__
> method.  When run with IronPython in the shell (or with CPython), you
> get the expected result:
> 
> C:\>"c:\Programs\IronPython 2.7\ipy.exe" Program.py
> 0
> 1
> 2
> 3
> 4
> 
> C:\>c:\Python27\python.exe Program.py
> 0
> 1
> 2
> 3
> 4
> 
> Underneath, of course, this is doing a[0], a[1], a[2], a[3], a[4], and
> stopping when a[5] raises an IndexError.
> 
> When I run this in Visual Studio, the debugger catches the IndexError,
> so this doesn't work.  It seems like the exception should be allowed
> to propagate further, so that the iteration works - but maybe this
> just isn't compatible with how the debugger works?
> 
> (It's easy enough to fix this by defining _iter__, of course).
> 
> Is this a bug?  Or just a limitation of how the debugging environment
> works?

If you hit F5 and continue execution it should keep on running.  You can 
also disable breaking on exceptions via Debug->Exceptions and uncheck the
"thrown" column for CLR exceptions.  It should just be breaking so you can
look around and seeing what's going on.





More information about the Ironpython-users mailing list