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 <1438386763.61.0.0168813953098.issue24726@psf.upfronthosting.co.za>
In-reply-to
Content
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 http://bugs.python.org/msg247358 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 http://bugs.python.org/issue10977) 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.
History
Date User Action Args
2015-07-31 23:52:43rhettingersetrecipients: + rhettinger, terry.reedy, Mark.Shannon, eric.snow, mpaolini
2015-07-31 23:52:43rhettingersetmessageid: <1438386763.61.0.0168813953098.issue24726@psf.upfronthosting.co.za>
2015-07-31 23:52:43rhettingerlinkissue24726 messages
2015-07-31 23:52:43rhettingercreate