This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Alexander Gosselin
Recipients Alexander Gosselin, Jim Fasarakis-Hilliard
Date 2017-04-21.17:35:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1492796120.43.0.97856581395.issue30130@psf.upfronthosting.co.za>
In-reply-to
Content
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')
History
Date User Action Args
2017-04-21 17:35:20Alexander Gosselinsetrecipients: + Alexander Gosselin, Jim Fasarakis-Hilliard
2017-04-21 17:35:20Alexander Gosselinsetmessageid: <1492796120.43.0.97856581395.issue30130@psf.upfronthosting.co.za>
2017-04-21 17:35:20Alexander Gosselinlinkissue30130 messages
2017-04-21 17:35:20Alexander Gosselincreate