[英]Does the Python 3.7+ spec guarantee `collections.OrderedDict is not dict`?
Does the Python spec guarantee that collections.OrderedDict is not dict
will always evaluate to True? Python 规范是否保证collections.OrderedDict is not dict
将始终评估为 True? Have the devs ever expressed they will maintain collections.OrderedDict
and dict
as separate data types?开发人员是否曾表示他们会将collections.OrderedDict
和dict
维护为单独的数据类型?
In other words is it expected that this code is "future proof" for new Python versions?换句话说,对于新的 Python 版本,是否预期此代码是“面向未来的”?
# several ways to mostly say the same thing
assert collections.OrderedDict is not dict
assert issubclass(collections.OrderedDict, dict)
assert not issubclass(dict, collections.OrderedDict)
a = dict()
b = collections.OrderedDict()
assert not isinstance(a, collections.OrderedDict)
assert isinstance(b, dict)
I think this would have to be true.我认为这必须是真的。 The specification of OrderedDict
says that comparisons between them are order-sensitive. OrderedDict
的规范说它们之间的比较是顺序敏感的。 But comparisons of ordinary dict
objects are not order-sensitive.但是普通dict
对象的比较不是顺序敏感的。 If the two classes were the same, this difference couldn't exist.如果两个类相同,则不会存在这种差异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.