This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.frederich
Recipients eric.frederich, eric.snow, rhettinger
Date 2015-07-22.17:04:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1437584641.0.0.00317519120009.issue24685@psf.upfronthosting.co.za>
In-reply-to
Content
After watching the PyCon talk Super considered super[1] and reading the corresponding blog post[2] I tried playing with dependency injection.

I was surprised to notice that the example he gave did not work if I swap the order of the classes around.  I think it should have.  See attached file.

I think this is a bug in collections.OrderedDict
OrderedDict is not well-behaved as far as cooperative subclassing is concerned.

The source code is hard wired with a keyword argument dict_setitem=dict.__setitem__ which it then calls at the end with dict_setitem(self, key, value)

A quick search of github for dict_setitem shows that this
bad practice seems be making its way into other projects

If dict_setitem keyword arg is really necessary to have, then maybe:

    (a) have it default to None
    (b) at the end of __setitem__ do something like:

        if dict_setitem is not None:
            return dict_setitem(self, key, value)
        
        super(OrderedDict, self).__setitem__(key, value)

After a discussion on #py-dev this seemed like a reasonable request (not necessarily the implementation, but the idea that OrderedDict should cooperate).
I tested this against the C implementation of OrderedDict in Python 3.5 and noticed that it doesn't cooperate either.


[1] https://www.youtube.com/watch?v=EiOglTERPEo
[2] https://rhettinger.wordpress.com/2011/05/26/super-considered-super/
History
Date User Action Args
2015-07-22 17:04:01eric.frederichsetrecipients: + eric.frederich, rhettinger, eric.snow
2015-07-22 17:04:00eric.frederichsetmessageid: <1437584641.0.0.00317519120009.issue24685@psf.upfronthosting.co.za>
2015-07-22 17:04:00eric.frederichlinkissue24685 messages
2015-07-22 17:04:00eric.frederichcreate