[pypy-dev] Support for __getitem__ in rpython?

Armin Rigo arigo at tunes.org
Thu Dec 11 14:53:47 CET 2008

Hi Hakan,

On Tue, Dec 09, 2008 at 08:14:35PM +0100, Hakan Ardo wrote:
> class arr2d:
>     def __init__(self,w,h):
>         self.width=w
>         self.height=h
>         self.data=[i for i in range(w*h)]
>     def __getitem__(self,i):
>         if isinstance(i,int):
>             return self.data[i]
>         elif len(i)==2:
>             return self.data[i[1]*self.width + i[0]]
>         else:
>             raise TypeError
>     __getitem__._annspecialcase_ = 'specialize:argtype(0)'

That's the wrong annotation.  For this case, it should be
'specialize:argtype(1)' in order to get two versions of __getitem__,
compiled for the two types that can be seen: integers and tuples.

A bientot,


More information about the Pypy-dev mailing list