Message12790

Author jeff.allen
Recipients jeff.allen
Date 2019-11-25.00:06:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1574640413.94.0.987761584212.issue2838@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-11-25 00:06:54jeff.allensetrecipients: + jeff.allen
2019-11-25 00:06:53jeff.allensetmessageid: <1574640413.94.0.987761584212.issue2838@roundup.psfhosted.org>
2019-11-25 00:06:53jeff.allenlinkissue2838 messages
2019-11-25 00:06:53jeff.allencreate