"in" / "not in" do not work as expected.
sparkslabs opened this issue · 2 comments
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
- Batavia version - 3.4.0-dev.19
- Batavia git hash -- 458cb41 (Dated Sun Mar 4 15:26:23 2018 +0800)
- Ubuntu Linux 16.04.04 -- LTS
- Python -- 3.5.2
- node -- v6.13.1
- npm -- 5.7.1
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.
Thanks for the comprehensive bug report! Looks like the definition of __contains__
on lists is a bit naïve.
Is this still open? @vn-ki seems to have solved this.