Message247136
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/ |
|
Date |
User |
Action |
Args |
2015-07-22 17:04:01 | eric.frederich | set | recipients:
+ eric.frederich, rhettinger, eric.snow |
2015-07-22 17:04:00 | eric.frederich | set | messageid: <1437584641.0.0.00317519120009.issue24685@psf.upfronthosting.co.za> |
2015-07-22 17:04:00 | eric.frederich | link | issue24685 messages |
2015-07-22 17:04:00 | eric.frederich | create | |
|