Search code examples
pythonsubclassdeque

how to set maxlen when subclassing a deque


I am trying to subclass a deque, but can't work out how to set the maxlen.

is there a __maxlen__ ?

EDIT: - is the following 'Bad' python?

from collections import deque

class MinMax(deque):
    def __init__(self):
        deque.__init__(self, maxlen=2)

mm = MinMax()

Solution

  • Call the super-class constructor:

    class dequePlus(collections.deque):
        def __init__(self, iterable):
            collections.deque.__init__(self, iterable, 100)