Re: [pyatl] Good (code | tutorial) on (designing proxies | modifying attribute access)?

From: user 7.
Sent on: Sunday, December 19, 2010 12:41 PM

On Sun, Dec 19, 2010 at 9:27 AM, Leif Poorman <[address removed]> wrote:
Hi, everybody. ?If this is an incorrect list to post stuff like this,
just let me know. ?It's about some fundamentals of python, though, so
I thought it might make a good discussion.

I was trying to see how well I understood attribute access in python.
So, I tried to design a class to proxy an object, intercepting gets,
sets, and dels. ?My original goal was to also understand its behavior
when subclassed. ?Simple, right? ?Well, let's just say I don't
understand attributes as well as I thought I did. ?Add inheritance,
and I bet I hardly understand at all.

I can't find a good tutorial on designing proxy classes, anyone know
of one? ?If not, do you have a favorite Proxy class from a library
(preferably with a clean, well-commented implementation)? ?A lot of
the implementations of libraries' proxy classes I've looked at have
strange hacks. ? Last resort, can you recommend a good article on
attribute access?

Thanks in advance,

#### You can stop reading here, if you want. ?What follows is a semi-rant. ####
I've already asked this on IRC; here are the comments you don't have
to make, they've been made already:

# "Why are you proxying? ?That is bad, for unspecified reasons!"

I'd be interested in hearing the specific reasons, and the alternatives.

# "Proxying is useless!"
# Me: "what if I want to instrument unrelated classes A, B, C, for
profiling/logging/etc. ?Writing a LoggingProxy/etc., seems like the
best solution to me."
# "use the profile module"
# Me: "what if you don't want to profile time spent, but some other
strange metric that comes up? ?Of course I am going to use
well-established tools for well-established problems, but my question
was about how to handle instrumentation generally. ?Specifically, it
was about how to design proxies."
# "don't use proxies, they're hard to write correctly, aren't useful,
and there are alternatives"

Again, what are the alternatives? ?I guess one alternative might be
metaclasses, but that doesn't really get around the "hard to write
correctly" problem, does it? ?And what if I don't want to touch
classes A, B, C, even to add a metaclass?

# "read the docs on getattr and setattr"
Gee, why didn't I think of that?

Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Leif Poorman ([address removed]) from PyAtl: Atlanta Python Programmers.
To learn more about Leif Poorman, visit his/her member profile:
To unsubscribe or to update your mailing list settings, click here:
Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]

Michael Langford

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy