#!/usr/bin/env python from collections import OrderedDict class LoggingDict(dict): """ Dummy class loggs entries to dict. Supports cooperative inheritance through use of super """ def __setitem__(self, k, v): print('setting %-8r to %r' % (k, v)) return super(LoggingDict, self).__setitem__(k, v) class OrderedLoggingDict1(LoggingDict, OrderedDict): """ Dependency injected class that works """ pass class OrderedLoggingDict2(OrderedDict, LoggingDict): """ Dependency injected class that doesn't work """ pass old1 = OrderedLoggingDict1() old2 = OrderedLoggingDict2() print('adding something to class with (LoggingDict, OrderedDict)') old1['hooray'] = 'it worked' print('adding something to class with (OrderedDict, LoggingDict)') old2['hooray'] = 'it worked'