Ivan Semochkin Ivan Semochkin - 6 months ago 45
Python Question

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

I notice when I create class in python2 it stores attributes in


>>> class A(object):
... pass
>>> A.__dict__

But in python3

>>> class A(object):
... pass
>>> A.__dict__

Is there any difference between two of them?


There is no real difference, it just got renamed.

When it was proposed to expose the type in the typing module in issue #14386, the object was renamed too:

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).

The change made it into Python 3.3, so in Python 3.2 you'll still see the old name.