On 20 Mar 2014 06:24, "Antoine Pitrou" <solip...@pitrou.net> wrote: > > On Wed, 19 Mar 2014 19:32:50 +0000 > Brett Cannon <bcan...@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
Graeme Dumpleton has also subsequently written a library to handle easier creation of correct proxy types: https://pypi.python.org/pypi/wrapt It isn't as simple as changing one lookup function though - abstract.c reads the type slots directly, and those are already hairy performance critical code paths (especially the binary operator type dispatch). Cheers, Nick. > > Regards > > Antoine. > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com