delegation pattern via descriptor

kedra marbun kedra.marbun at gmail.com
Wed Jul 7 19:52:50 EDT 2010


On Jul 6, 12:11 pm, Steven D'Aprano <steve-REMOVE-
T... at cybersource.com.au> wrote:
> On Mon, 05 Jul 2010 21:12:47 -0700, kedra marbun wrote:
> > On Jul 5, 7:49 am, Gregory Ewing <greg.ew... at canterbury.ac.nz> wrote:
> >> kedra marbun wrote:
> >> > now, i'm asking another favor, what about the 2nd point in my 1st
> >> > post?
>
> >> Your original post has dropped off my newsscope, so you'll have to
> >> remind me what the 2nd point was.
>
> >> --
> >> Greg
>
> > it's like 'name', it's about info that i think should be passed to
> > descriptor's __{get|set|delete}__. i wonder what are the reasons for not
> > passing the class on which the descriptor is attached to, what pattern
> > is encouraged by this?
>
> Perhaps I'm missing the context, but since the descriptor is passed the
> instance, you can easily get the class with type(self) or self.__class__.
> There's no need to pass the class as a separate argument.
>
> --
> Steven

no, the class that i meant is the one that actually has the descriptor
in its __dict__, not instance.__class__

the class obj that you said unecessary-as-arg is what __get__ receives
as the 3rd arg

class Desc:
	def __get__(*args): print(args)

class a:
	v0 = Desc()

class b(a): pass

b().v0	#(desc, b(), b)



More information about the Python-list mailing list