Issue2645

classification
Title: pop method returns wrong result with Java LinkedList
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jamesmudd, jeff.allen, stefan.richthofer, zyasoft
Priority: Keywords:

Created on 2017-11-22.18:58:50 by jamesmudd, last changed 2018-03-08.17:30:33 by stefan.richthofer.

Messages
msg11674 (view) Author: James Mudd (jamesmudd) Date: 2017-11-22.18:58:50
pop should return the last item in the list (https://docs.python.org/2/tutorial/datastructures.html#more-on-lists) which works correctly with ArrayList but fails with LinkedList e.g.
    >>> stack = [1,2,3]
    >>> stack.pop()
    3  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Correct
    >>> from java.util import ArrayList
    >>> jl = ArrayList([1,2,3])
    >>> jl.pop()
    3  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Correct
    >>> from java.util import LinkedList
    >>> jll = LinkedList([1,2,3])
    >>> jll.pop()
    1  <<<<<<<<<<<<<<<< First entry not last?

I think this is because LinkedList implements Deque with defines the pop method to return the first item not the last. This might not be fixable as both results are "correct" depending on what you define pop to do.
msg11768 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-08.08:43:59
We don't claim that LinkedList is a Python list which would imply the expected behaviour (or even a collections.MutableSequence), so I think its pop method should do what LinkedList.pop is supposed to do. (Imagine the surprise if it did otherwise.)

For me, your example calls slightly into question that java.util.List should have all the methods of a Python list. Or at any rate, reminds us of the limitations of that idea.

>>> from java.util import LinkedList, ArrayList, List, Deque
>>> List.pop
<method 'pop' of 'java.util.List' objects>
>>> 'pop' in dir(List)
True

It must surely be the result of JavaProxyList (and PyJavaType). It only supplies the implementation of interface methods not already provided by the actual class.

Would you be content to agree this is not a bug?
msg11769 (view) Author: James Mudd (jamesmudd) Date: 2018-03-08.10:04:43
Yes I would agree that this is not a bug. It was more of an observation while looking at this code.

This can be closed as not to be fixed.
msg11770 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-08.16:39:50
Good. Interesting, though.
msg11771 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2018-03-08.17:30:33
Maybe we should regard this a documentation issue.
History
Date User Action Args
2018-03-08 17:30:33stefan.richthofersetnosy: + stefan.richthofer
messages: + msg11771
2018-03-08 16:39:50jeff.allensetnosy: + zyasoft
messages: + msg11770
2018-03-08 10:04:43jamesmuddsetmessages: + msg11769
2018-03-08 08:44:00jeff.allensetnosy: + jeff.allen
messages: + msg11768
2017-11-22 18:58:50jamesmuddcreate