Message12790
Benoit Cantin makes the following observation on 2.7.2b2:
"""
from java.util import ArrayList
test = ArrayList()
test.remove("aaa")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: aaa is not in list
The same code returns False with Jython 2.7b3 which is correct according to the documentation: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/ArrayList.html#remove(java.lang.Object)
If I remember correctly, a teammate also found this bug in version 2.7.1.
"""
This (I suppose) is because we have given ArrayList some behaviour that is Python-like. We have noted in #2645 the behaviour of LinkedList.pop(), which is surprising (to some) in that it removes from the opposite end from Python list.pop().
The idea that we dress Java containers as their Python near-equivalents is attractive because we will often be able to pass an object returned from Java directly to Python code expecting (say) a list. Unfortunately, it creates these surprises. If the receiving Python code expects pop() to work as advertised, it will get the wrong result. We have perhaps wrapped remove() in order that Python code doesn't malfunction that calls remove() expecting this behaviour of list.remove.
I think that an object claiming to have Java type should work as that type, and where we want it to behave as a Python list, it should be wrapped to do so, explicit being better than implicit here. |
|
Date |
User |
Action |
Args |
2019-11-25 00:06:54 | jeff.allen | set | recipients:
+ jeff.allen |
2019-11-25 00:06:53 | jeff.allen | set | messageid: <1574640413.94.0.987761584212.issue2838@roundup.psfhosted.org> |
2019-11-25 00:06:53 | jeff.allen | link | issue2838 messages |
2019-11-25 00:06:53 | jeff.allen | create | |
|