Immutable view classes - inherit from dict or from Mapping?

Andreas R Maier andreas.r.maier at gmx.de
Mon Apr 12 12:01:57 EDT 2021


Hi,
I have written some classes that represent immutable views on collections (see "immutable-views" package on Pypi).

Currently, these view classes inherit from the abstract collection classes such as Mapping, Sequence, Set. However, they implement the read-only methods of dict, list and set, which provides some more methods compared to the abstract collection classes. For example, class "dict" provides copy() or __reversed__() and the newer OR-operator methods all of which are not defined on the abstract class "Mapping".

Note that the view classes do not provide any of the modifying methods of "dict" and "list", because after all the views are supposed to be immutable.

My question is, should the dict view class inherit from Mapping or from dict, and likewise, should the list view class inherit from Sequence or from list?

Thanks
Andy



More information about the Python-list mailing list