beeware / batavia

A JavaScript implementation of the Python virtual machine.
http://pybee.org/batavia
Other
1.39k stars 424 forks source link

For loops with sequence objects #762

Closed SebStreb closed 5 years ago

SebStreb commented 5 years ago

I was trying to use for loops with iterable objects (implementing iter method or len and getitem methods). I discovered that currently batavia does not accept objects implementing the sequence protocol (len and getitem methods).

The following code works on normal python but not on batavia :

class Test:
    def __init__(self, l):
        self.l = l
    def __len__(self):
        return len(self.l)
    def __getitem__(self, index):
        return self.l[index]
t = Test([1 ,2, 3, 6])

total = 0
for i in t:
    total = total + i
    print(i, total)
print('Done.')

I'm using python3.5 in a virtual environment running on macOS 10.14.1.

martica commented 5 years ago

Thanks for the report and the fix!