[issue25410] Clean up and fix OrderedDict
Raymond Hettinger
report at bugs.python.org
Sun Nov 4 16:31:17 EST 2018
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
> Maybe it's considered undefined behavior for a subclass to use
> a method of one of its bases which it has overriden.
In general, it's true that if OrderedDict is a subclass of dict, then it would have no defense against someone making a direct call to the dict base class. Such a call should be expected to violate the OrderedDicts invariants.
> it's a complete coin toss on whether one of the many internal
> API function will set an attribute or name via PyDict_SetItem
> or PyObject_SetItem.
Not really. The CPython source is supposed to only call PyDict_SetItem when the target is known to be an exact dictionary. If you find a case where that isn't true, please file a bug report and we'll fix it.
> It might be more appropriate to start a new issue for this, but I'll > leave that decision to somehow who would know for sure.
No need. We've known about this sort of problem for years. See https://bugs.python.org/issue10977 for example. There isn't really much we could do about it without causing other issues that would be worse.
FWIW, this doesn't seem to be a problem in practice. Further, OrderedDict is expected to become less relevant now that regular dicts are order preserving.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue25410>
_______________________________________
More information about the Python-bugs-list
mailing list