It appears as if the __reversed__ attribute of lists in Jython is not implemented. I don't get the results you describe, if I call
getattr([], '__reversed__')
in Python 2.5.2, I get
>>> [].__reversed__
<built-in method __reversed__ of list object at 0x7f72581d7050>
And in Jython 2.5.1, I get
>>> [].__reversed__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute '__reversed__'
If it's returning True
or False
respectively, then you're probably not using a standard Python list.
In any case, it appears as if Jython doesn't support the __reversed__ attribute of lists to indicate that it is reversible. According to the documentation, this feature appears to have been added to the CPython implementation in Python 2.6, which might explain why it doesn't appear in Jython 2.5.1. I do find that __reversed__ appears in Python 2.5.2, so it may have been back-ported to CPython, but just not officially supported.
For now, you can suggest that cmd2 be patched with something like the following:
def can_be_reversed(o):
"return True if an object can be reversed by reverse()"
return hasattr(o, '__reversed__') or \
hasattr(o, '__len__') and hasattr(o, '__getitem__')