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
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
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
É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
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 are
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
Changes by Eric Frederich eric.freder...@gmail.com:
Removed file: http://bugs.python.org/file39998/inj2.py
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24685
___
Changes by Eric Frederich eric.freder...@gmail.com:
Added file: http://bugs.python.org/file3/inj2.py
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24685
___
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
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
Changes by Raymond Hettinger raymond.hettin...@gmail.com:
--
assignee: - rhettinger
versions: +Python 3.6 -Python 2.7, Python 3.5
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24685
___
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
12 matches
Mail list logo