Why doesn't OrderedDict use super?

淺唱寂寞╮ 提交于 2019-12-03 16:46:05

It's a microoptimization. Looking up a dict_setitem argument is slightly faster than looking up dict.__setitem__ or super().__setitem__.

This might cause problems with multiple inheritance if you have another class that overrides __setitem__, but OrderedDict isn't designed for that kind of diamond-structured method overriding anyway. For OrderedDict to support that, it'd have to make very careful guarantees about what another class's methods might see if they try to index the OrderedDict while the ordering information is inconsistent with the dict structure. Such guarantees would be way too messy to make.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!