Author rhettinger
Recipients Mark.Shannon, eric.snow, mpaolini, rhettinger, terry.reedy
Date 2015-07-31.23:52:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
There is a bug in _PyObject_GenericSetAttrWithDict() Objects/object.c   where a calls are made to PyDict_SetItem() and PyDict_DelItem() without checking first checking for PyDict_CheckExact(). 

* In PEP 372, OrderedDict was consciously specified to be a subclass of regular dicts in order to improve substitutability for dicts in most existing code.  That decision had some negative consequences as well.  It is unavoidable the someone can call the parent class directly and undermine the invariants of the subclass (that is a fact of life for all subclasses that maintain their own state while trying to stay in-sync with state in the parent class -- see for an example).

With pure python code for the subclass, we say, "don't do that". I'll add a note to that effect in the docs for the OD (that said, it is a general rule that applies to all subclasses that have to stay synchronized to state in the parent).

In C version of the OD subclass, we still can't avoid being bypassed (see and having our subclass invariants violated.  Though the C code can't prevent the invariants from being scrambled it does have an obligation to not segfault and to not leak something like "OrderedDict([<NULL>])".  Ideally, if is possible to detect an invalid state (i.e. the linked link being out of sync with the inherited dict), then a RuntimeError or somesuch should be raised.
Date User Action Args
2015-07-31 23:52:43rhettingersetrecipients: + rhettinger, terry.reedy, Mark.Shannon, eric.snow, mpaolini
2015-07-31 23:52:43rhettingersetmessageid: <>
2015-07-31 23:52:43rhettingerlinkissue24726 messages
2015-07-31 23:52:43rhettingercreate