[Python-Dev] Making proxy types easier to write and maintain (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Wed Mar 19 22:54:39 CET 2014
- Previous message: [Python-Dev] Making proxy types easier to write and maintain
- Next message: [Python-Dev] Making proxy types easier to write and maintain
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 20 Mar 2014 06:24, "Antoine Pitrou" <solipsis at pitrou.net> wrote:
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
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 at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20140320/907f0cc7/attachment.html>
- Previous message: [Python-Dev] Making proxy types easier to write and maintain
- Next message: [Python-Dev] Making proxy types easier to write and maintain
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]