assigning a custom mapping type to __dict__

Daniel Cer Daniel.Cer at Colorado.EDU
Tue Mar 1 11:38:58 EST 2005


> > Why not just inherit from dict? That seems to work.
>
> Because that isn't the question - Steven knows how to make it work, what he's
> curious about is why things are the way they are :)

Sorry, didn't mean to be a pest :)

I guess I assumed Steve already knew that he could inherit from dict.
That being said, I was wondering why pragmatically this wouldn't be the
right thing to do (in order to do what he seemed to want to do).

<me> braces self for the true but not always too informative response of
'in principle, it's best to use the most abstract interface possible'</me>

-Dan


>
> Anyway, a quick look suggests that it is due to typeobject.c using the concrete
> PyDict_* API calls [1] to manipulate tp_dict, rather than the abstract
> PyMapping_* calls [2]. The reason behind using the concrete API is, presumably,
> a question of speed :)
>
> Cheers,
> Nick.
>
> [1] http://www.python.org/dev/doc/devel/api/dictObjects.html
> [2] http://www.python.org/dev/doc/devel/api/mapping.html
> --
> Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
> ---------------------------------------------------------------
>              http://boredomandlaziness.skystorm.net
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list