python2中的dict_proxy和python3中的mappingproxy有什么区别?

What the difference between dict_proxy in python2 and mappingproxy in python3?

我注意到当我在 python2 中创建 class 时,它将属性存储在 dict_proxy 对象中:

>>> class A(object):
...     pass
>>> A.__dict__
dict_proxy({....})

但是在python3__dict__returnsmappingproxy

>>> class A(object):
...     pass
>>> A.__dict__
mappingproxy({....})

两者有什么区别吗?

没有真正的区别,它just got renamed

issue #14386中提议在typing模块中公开类型时,对象也被重命名:

I'd like to bikeshed a little on the name. I think it should be MappingProxy. (We don't use "view" much but the place where we do use it, for keys/values/items views, is very different I think. Also collections.abc already defines MappingView as the base class for KeysView and friends.)

Anyway, you are not the first one who remarks that we already use "view" to define something else, so I wrote a new patch to use the "mappingproxy" name (exposed as types.MappingProxyType).

更改 made it into Python 3.3,因此在 Python 3.2 中您仍然会看到旧名称。