You need to call the list initializer:
class MyList(list): def __init__(self, li): super(MyList, self).__init__(li)
Assigning the self function in a function simply replaces the local variable with a list, does not assign the instance anything:
>>> class MyList(list): ... def __init__(self, li): ... super(MyList, self).__init__(li) ... >>> ml = MyList([1, 2, 3]) >>> ml [1, 2, 3] >>> len(ml) 3 >>> type(ml) <class '__main__.MyList'>
source share