delegation pattern via descriptor

Gregory Ewing greg.ewing at canterbury.ac.nz
Thu Jul 8 06:10:48 EDT 2010


kedra marbun wrote:
> i wonder what are the reasons for
> not passing the class on which the descriptor is attached to, what
> pattern is encouraged by this?

The same answer applies. It's assumed that you will be
writing a custom piece of code for each attribute of
each class, and giving each one its own descriptor.

By the time you get to the get or set method of a
descriptor, you've already dispatched on both the
class and attribute name. There is not usually any
point in funnelling things back into a single function
and then dispatching on the class or name again.
Passing the class or name would just add overhead that
was unnecessary in the majority of use cases.

-- 
Greg



More information about the Python-list mailing list