[Python-Dev] Making proxy types easier to write and maintain
Antoine Pitrou
solipsis at pitrou.net
Wed Mar 19 21:22:42 CET 2014
On Wed, 19 Mar 2014 19:32:50 +0000
Brett Cannon <bcannon at gmail.com> wrote:
> >
> > In http://bugs.python.org/issue19359#msg213530 I proposed to introduce a
> > "proxy
> > protocol" (__proxy__ / tp_proxy) that would be used as a fallback by
> > _PyObject_LookupSpecial to fetch the lookup target, i.e.:
> >
> > def _PyObject_LookupSpecial(obj, name):
> > tp = type(obj)
> > try:
> > return getattr(tp, name)
> > except AttributeError:
> > return getattr(tp.tp_proxy(), name)
> >
> > What do you think?
> >
>
> Without having the code in front of me, would this only be for magic
> methods and attributes, or all attributes? IOW would this mean that if I
> assign an object to __proxy__ it would take care of the uses of __getattr__
> for proxying?
In a first approach it would be only for magic methods and attributes.
It if proves successful, perhaps it can be later expanded to also be
used for regular lookups.
By the way, Benjamin pointed me to a prior discussion:
http://bugs.python.org/issue643841
Regards
Antoine.
More information about the Python-Dev
mailing list