Raymond Hettinger added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24726>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to