classification
Title: Keep the link to Python implementation of OrderedDict
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: abarry, eric.snow, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2015-11-14 08:12 by serhiy.storchaka, last changed 2015-11-20 18:06 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
OrderedDict_python_impl.patch serhiy.storchaka, 2015-11-14 08:12 review
Messages (5)
msg254645 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-14 08:12
For now C implementation of OrderedDict totally overrides Python implementation.

>>> import collections
>>> collections.OrderedDict.__init__
<slot wrapper '__init__' of 'collections.OrderedDict' objects>                                                                

The only way to get Python implementation of OrderedDict is to block the _collections module and reload the collections module.

>>> del sys.modules['collections']
>>> del sys.modules['collections.abc']
>>> sys.modules['_collections'] = None
>>> import collections
>>> collections.OrderedDict.__init__
<function OrderedDict.__init__ at 0xb6f6da4c>

But this also blocks collections.deque, collections.defaultdict, and the acceleration of collections.Counter.

As long as C implementation of OrderedDict still has some bugs (and I'm not sure we will have fixed all them before releasing 3.5.1), I think it would be good to have a workaround for applications that encounter one of still not fixed bugs.

I propose to keep a reference to Python implementation as collections._OrderedDict. This is not a public interface and we don't promise existing this name in future releases. This is just a way to make a workaround for the time while C implementation is not stable enough. I hope we will got rid from it in 3.7.

A workaround for an application that suffers from OrderedDict bug:

import collections
try:
    collections.OrderedDict = collections._OrderedDict
except AttributeError:
    pass
msg254698 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-11-15 22:29
I think we should stick with fixing bugs as found (even if that process spills into 3.5.2).  The current tests do a good job of making sure the basic functionality is in place and there has been use in the field.  Also, you've already done a good job fixing a few of the most egregious bugs.

Likewise should have an aversion to temporary APIs like _collections and to API changes between micro releases.  In general, this strategy is likely to cause more pain than it alleviates.  So, put me down for -1 on this one.
msg254702 - (view) Author: Anilyka Barry (abarry) * (Python triager) Date: 2015-11-16 00:59
I would personally suggest a more permanent and accessible way, in the way the decimal module handles it. I'd add a '_pycollections' module holding the pure Python implementations of OrderedDict and _count_elements, then have the collections package import them if the C accelerators don't work.

While the '_pydecimal' module is not guaranteed to remain across versions, successfully importing it means that you are guaranteed to use the pure Python version of it. In the same direction, successfully importing OrderedDict from _pycollections would guarantee that you're using the pure Python version of it.

This would have the side-effect of allowing people relying on the pure Python implementation details to use them (see #25315).
msg254707 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-11-16 03:13
> This would have the side-effect of allowing people relying
> on the pure Python implementation details to use them

Right.  That's why we don't want to do this.
msg255000 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2015-11-20 17:24
I agree with Raymond.
History
Date User Action Args
2015-11-20 18:06:38serhiy.storchakasetstatus: open -> closed
resolution: rejected
stage: patch review -> resolved
2015-11-20 17:24:23eric.snowsetmessages: + msg255000
2015-11-16 03:13:10rhettingersetmessages: + msg254707
2015-11-16 00:59:01abarrysetnosy: + abarry
messages: + msg254702
2015-11-15 22:29:46rhettingersetmessages: + msg254698
2015-11-14 08:12:48serhiy.storchakacreate