Message10672

Author zyasoft
Recipients jsaiz, zyasoft
Date 2016-02-01.20:48:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1454359710.69.0.869290439504.issue2456@psf.upfronthosting.co.za>
In-reply-to
Content
So the problem here is that Python's list.remove (https://docs.python.org/2/library/stdtypes.html#mutable-sequence-types) has different semantics than java.util.List (https://docs.oracle.com/javase/7/docs/api/java/util/List.html#remove(int)), but of course the same as remove(Object) when the List contains integers...

See this note in NEWS (https://github.com/jythontools/jython/blob/master/NEWS#L166)

  Potentially backwards breaking changes, removing silent errors:

    - remove method on proxied List objects now follows Python
      sematics: a ValueError is raised if the item is not found in the
      java.util.List. In the past, Java semantics were used, with a
      boolean returned indicating if the item was removed or
      not. Given how this interacted with Jython, such remove
      invocations were in the past silent, and perhaps were actually a
      bug.

I'm not sure how we can reconcile, other than to document that the equivalent Python operation would be list.pop(0), which is available:

$ bin/jython 
Jython 2.7.1b2 (default:f58d86b21716, Jan 26 2016, 14:07:09) 
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_80
Type "help", "copyright", "credits" or "license" for more information.
>>> from java.util import ArrayList
>>> x = ArrayList()
>>> x.add(42)
True
>>> x.remove(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 0 is not in list
>>> y = list()
>>> y.append(
y.append(   
>>> y.append(42)
>>> y.remove(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: list.remove(x): x not in list
>>> from java.lang import Integer
>>> y.remove((Integer(0))
... )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: list.remove(x): x not in list
>>> y.remove(Integer(0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: list.remove(x): x not in list
>>> x.remove(Integer(0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: 0 is not in list
>>> x.pop(0)
42
>>> x
[]
History
Date User Action Args
2016-02-01 20:48:30zyasoftsetmessageid: <1454359710.69.0.869290439504.issue2456@psf.upfronthosting.co.za>
2016-02-01 20:48:30zyasoftsetrecipients: + zyasoft, jsaiz
2016-02-01 20:48:30zyasoftlinkissue2456 messages
2016-02-01 20:48:29zyasoftcreate