[Python-ideas] RFC: PEP: Add dict.__version__

Steven D'Aprano steve at pearwood.info
Sun Jan 10 12:57:32 EST 2016


On Sun, Jan 10, 2016 at 11:48:35AM -0500, Neil Girdhar wrote:

[...]
> > v = mydict.__version__
> > maybe_modify(mydict)
> > if v != mydict.__version__:
> >     print("dict has changed")
> 
> 
> This is exactly what I want to avoid.  If you want to do something like
> this, I think you should do it in regular Python by subclassing dict and
> overriding the mutating methods.

That doesn't help Victor, because exec need an actual dict, not 
subclasses. Victor's PEP says this is a blocker.

I can already subclass dict to do that now. But if Victor's suggestion 
is accepted, then I don't need to. The functionality will already exist. 
Why shouldn't I use it?


> What happens if someone uses a custom Mapping?

If they inherit from dict or UserDict, they get this functionality for 
free. If they don't, they're responsible for implementing it if they 
want it.


> Do all custom Mappings need to implement __version__?

I believe the answer to that is No, but the PEP probably should clarify 
that.


-- 
Steve


More information about the Python-ideas mailing list