Issue2645
Created on 2017年11月22日.18:58:50 by jamesmudd, last changed 2019年11月26日.16:29:28 by zyasoft.
| 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. |
|||
| msg12802 (view) | Author: Jim Baker (zyasoft) | Date: 2019年11月26日.16:29:27 | |
I made a more detailed note in https://bugs.jython.org/issue2838, where I suggested a couple of possible changes through "hooks" to support the Java behavior instead of the semantic equivalence of what we do in Jython. So this could let pop, remove, etc, retain their Java semantics if desired. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2019年11月26日 16:29:28 | zyasoft | set | messages: + msg12802 |
| 2018年03月08日 17:30:33 | stefan.richthofer | set | nosy:
+ stefan.richthofer messages: + msg11771 |
| 2018年03月08日 16:39:50 | jeff.allen | set | nosy:
+ zyasoft messages: + msg11770 |
| 2018年03月08日 10:04:43 | jamesmudd | set | messages: + msg11769 |
| 2018年03月08日 08:44:00 | jeff.allen | set | nosy:
+ jeff.allen messages: + msg11768 |
| 2017年11月22日 18:58:50 | jamesmudd | create | |
Supported by Python Software Foundation,
Powered by Roundup