[Python-Dev] Making proxy types easier to write and maintain (original) (raw)

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 / tpproxy) that would be used as a fallback by > PyObjectLookupSpecial to fetch the lookup target, i.e.: > > def PyObjectLookupSpecial(obj, name): > tp = type(obj) > try: > return getattr(tp, name) > except AttributeError: > return getattr(tp.tpproxy(), 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