Alexander Gosselin added the comment:
Thanks for taking a look at this. I think array is little used, so registering
it as a member of some of the abstract base classes in collections could easily
have been overlooked.
One of the prerequisites for membership in MutableSequence is a .clear()
method, and array doesn't have one, though there is no reason why it shouldn't.
Here's the workaround that I'm using:
import array
import collections
class array(array.array,
collections.MutableSequence):
__slots__ = ()
def __reversed__(self):
# this is a bit hacky
return reversed(self.tolist())
def clear(self):
self.__setitem__(slice(None), self.__class__(self.typecode))
Here are some results:
>>> a = array('f', [1,2,3,4])
>>> list(reversed(a))
[4.0, 3.0, 2.0, 1.0]
>>> a.clear()
>>> a
array('f')
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue30130>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com