Python 3.0+collectionsterm
collections.UserList
type wrappers
A list wrapper exposing its contents via .data; a base for custom list classes.
Syntax
class MyList(collections.UserList): ...
Compared with subclassing list: slicing, concatenation and copying on a UserList give back an instance of your class rather than a plain list, and the payload sits in an ordinary list at .data that you can validate or swap out. The trade-off is that the object is not a list (isinstance(x, list) is False) and delegation makes it noticeably slower — hand .data or list(x) to code that expects the real thing.
Examples
from collections import UserList
l = UserList([1, 2])
l.append(3)
print(list(l)) # → [1, 2, 3]
See also
Open in the full glossarydocs.python.orgReport an inaccuracy