beeware / batavia

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

"in" / "not in" do not work as expected. #724

Open sparkslabs opened 6 years ago

sparkslabs commented 6 years ago

First of all thanks for writing this. I saw the recording of your talk on this on youtube from a pycon or similar and thought it worth trying. Works really well over all. Many thanks!

With that, the bug report...

Expected Behaviour

The following works in CPython:

resource_id = "foo"
user_resources_done = []

if resource_id not in user_resources_done:
    print("Gotta do that")
else:
    print("Done it")

Specifically it generates the following output:

>>> resource_id = "foo"
>>> user_resources_done = []
>>> if resource_id not in user_resources_done:
...     print("Gotta do that")
... else:
...     print("Done it")
... 
Gotta do that
>>> 

Current Behavior

In Batavia, if I use the same code, I get this:

Traceback (most recent call last):
  File "/tmp/tmpsrv0plrf", line 3, in <module>
ValueError: list.index(x): x not in list

Clearly this is a difference in behaviour.

Steps to reproduce

Using the testserver, copy and paste the above code into the "Run your code!" box, and hit "Run your code!"

Your Environment

Workaround

Obviously this can be worked around in Batavia, but I thought it enough of an issue to raise since the obvious workarounds would only work in Batavia with this bug, not in CPython nor Batavia without this bug.

freakboy3742 commented 6 years ago

Thanks for the comprehensive bug report! Looks like the definition of __contains__ on lists is a bit naïve.

noahhaasis commented 6 years ago

Is this still open? @vn-ki seems to have solved this.