[New-bugs-announce] [issue25623] Keep the link to Python implementation of OrderedDict

Serhiy Storchaka report at bugs.python.org
Sat Nov 14 03:12:48 EST 2015

New submission from Serhiy Storchaka:

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
    collections.OrderedDict = collections._OrderedDict
except AttributeError:

components: Library (Lib)
files: OrderedDict_python_impl.patch
keywords: patch
messages: 254645
nosy: eric.snow, rhettinger, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Keep the link to Python implementation of OrderedDict
type: enhancement
versions: Python 3.5, Python 3.6
Added file: http://bugs.python.org/file41038/OrderedDict_python_impl.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list