[issue24685] collections.OrderedDict collaborative subclassing

2016-04-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: Sorry Eric, I'm going to mark this as rejected. IMO this amounts to twisting the implementation into knots without any real payoff. I'm glad you enjoyed my Pycon talk and were inspired by it. -- resolution: -> rejected status: open -> closed ___

[issue24685] collections.OrderedDict collaborative subclassing

2015-07-24 Thread Eric Frederich
Eric Frederich added the comment: Éric (Araujo), Combinding defaultdict and OrderedDict is a little easier since one of them (defaultdict) has special behavior on getitem while the other (OrderedDict) has special behavior on setitem. I played with mixing those two myself and saw some issues a

[issue24685] collections.OrderedDict collaborative subclassing

2015-07-24 Thread Éric Araujo
Éric Araujo added the comment: FWIW I once helped a friend combine OrderedDict and defaultdict: https://gist.github.com/merwok/11268759 The behavior can be surprising if we don’t know what Raymond said about design choices in OrderedDict, but it was not hard (in the default+ordered case) to wo

[issue24685] collections.OrderedDict collaborative subclassing

2015-07-24 Thread Eric Frederich
Eric Frederich added the comment: I understand that in the general case you cannot just swap the order around and get the same behaviour. This LoggingDict just prints some stuff to the screen and delegates to super and so I believe it should work wherever it is placed in a cooperative hierarc

[issue24685] collections.OrderedDict collaborative subclassing

2015-07-23 Thread Raymond Hettinger
Raymond Hettinger added the comment: Eric, I believe you're profoundly misunderstanding my Pycon talk. The posted code is not expected "to work if I swap the order of the classes around" -- MRO's are controlled by the child classes (subject to a number of constraints) and the order classes ar

[issue24685] collections.OrderedDict collaborative subclassing

2015-07-23 Thread Eric Frederich
Eric Frederich added the comment: Attached, as inj3.py, is a version I made which seems to work with Python2 but not with Python3's C implementation of OrderedDict. I had to walk the MRO myself to get the unbound method to pass along as dict_setitem. With Python3 it doesn't look like doing th

[issue24685] collections.OrderedDict collaborative subclassing

2015-07-23 Thread Eric Frederich
Changes by Eric Frederich : Added file: http://bugs.python.org/file3/inj2.py ___ Python tracker ___ ___ Python-bugs-list mailing list Unsu

[issue24685] collections.OrderedDict collaborative subclassing

2015-07-23 Thread Eric Frederich
Changes by Eric Frederich : Removed file: http://bugs.python.org/file39998/inj2.py ___ Python tracker ___ ___ Python-bugs-list mailing list Un

[issue24685] collections.OrderedDict collaborative subclassing

2015-07-23 Thread Eric Frederich
Eric Frederich added the comment: Raymond, Thanks for the explanation of your reasoning. Could you please provide an example of how to create a cooperative subclass of OrderedDict? I have attempted to make one. I succeeded to make it work where the previous example failed but in doing made th

[issue24685] collections.OrderedDict collaborative subclassing

2015-07-22 Thread Raymond Hettinger
Raymond Hettinger added the comment: This is an intentional design choice. One reason for tightly coupling OrderedDict to dict was to preserve freedom for a C-implementation. Another reason was for performance. IIRC, using super() in __setitem__ slowed the OD from 10x slower than dicts to 2

[issue24685] collections.OrderedDict collaborative subclassing

2015-07-22 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- assignee: -> rhettinger versions: +Python 3.6 -Python 2.7, Python 3.5 ___ Python tracker ___ ___ Py

[issue24685] collections.OrderedDict collaborative subclassing

2015-07-22 Thread Eric Frederich
New submission from Eric Frederich: 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