Re: per instance descriptors

2006-12-07 Thread Simon Bunker
Carl Banks wrote: > Simon Bunker wrote: > >>Hi I have code similar to this: >> >>class Input(object): >> >> def __init__(self, val): >> self.value = val >> >> def __get__(self, obj, objtype): >> return self.value >> >> def __set__(self, obj, val): >> # do some c

Re: per instance descriptors

2006-12-07 Thread Simon Bunker
George Sakkis wrote: > [EMAIL PROTECTED] wrote: > > >>George Sakkis wrote: >> >>>Simon Bunker wrote: >>> >>> Hi I have code similar to this: class Input(object): def __init__(self, val): self.value = val def __get__(self, obj, objtype):

Re: per instance descriptors

2006-12-07 Thread George Sakkis
[EMAIL PROTECTED] wrote: > George Sakkis wrote: > > Simon Bunker wrote: > > > > > Hi I have code similar to this: > > > > > > class Input(object): > > > > > > def __init__(self, val): > > > self.value = val > > > > > > def __get__(self, obj, objtype): > > > return self.

Re: per instance descriptors

2006-12-07 Thread simon
George Sakkis wrote: > Simon Bunker wrote: > > > Hi I have code similar to this: > > > > class Input(object): > > > > def __init__(self, val): > > self.value = val > > > > def __get__(self, obj, objtype): > > return self.value > > > > def __set__(self, obj, val): >

Re: per instance descriptors

2006-12-06 Thread Carl Banks
Simon Bunker wrote: > Hi I have code similar to this: > > class Input(object): > > def __init__(self, val): > self.value = val > > def __get__(self, obj, objtype): > return self.value > > def __set__(self, obj, val): > # do some checking... only accept flo

Re: per instance descriptors

2006-12-06 Thread Gabriel Genellina
At Thursday 7/12/2006 01:58, George Sakkis wrote: Simon Bunker wrote: > Basically I want to have the Input class as a gateway that does lots of > checking when the attibute is assigned or read. > > I have had a look at __getattribute__(), but this gets very ugly as I > have to check if the attr

Re: per instance descriptors

2006-12-06 Thread George Sakkis
Simon Bunker wrote: > Hi I have code similar to this: > > class Input(object): > > def __init__(self, val): > self.value = val > > def __get__(self, obj, objtype): > return self.value > > def __set__(self, obj, val): > # do some checking... only accept flo

Re: Per instance descriptors ?

2006-03-23 Thread bruno at modulix
Steven Bethard wrote: (snip code) > > But that looks pretty nasty to me. > It sounds like your architecture > could use some redesigning Done - in much more sane way. Got rid of some more boilerplate and of the whole problem of per-instance descriptors BTW !-) I should probably sleep more

Re: Per instance descriptors ?

2006-03-23 Thread Steven Bethard
bruno at modulix wrote: > Using a class as a > decorator, I have of course only one instance of it per function - and > for some attributes, I need an instance per function call. Per function call? And you want the attributes on the function, not the result of calling the function? If so, that

Re: Per instance descriptors ?

2006-03-23 Thread bruno at modulix
Steven Bethard wrote: (some smart questions) Steven , I owe you a *big* thank. I knew they must have been something wrong, but couldn't point what. Now I see, and it's of course totally obvious. Using a class as a decorator, I have of course only one instance of it per function - and for some at

Re: Per instance descriptors ?

2006-03-23 Thread Steven Bethard
bruno at modulix wrote: > Steven Bethard wrote: >> Could you explain again why you don't want baaz to be a class-level >> attribute? > > Because the class is a decorator for many controller functions, and each > controller function will need it's own set of descriptors, so I don't > want to mess w

Re: Per instance descriptors ?

2006-03-23 Thread bruno at modulix
Steven Bethard wrote: > bruno at modulix wrote: > >> Hi >> >> I'm currently playing with some (possibly weird...) code, and I'd have a >> use for per-instance descriptors, (snip) >> >> class MyClass2(MyClass1): >> def __getattribute__(self, key): >> v = MyClass1.__getattribute__(self

Re: Per instance descriptors ?

2006-03-23 Thread bruno at modulix
Michael Spencer wrote: > Bruno Desthuilliers wrote: > (snip) > >> BTW, there may be other use case for per-instance descriptors... > > > Agreed. Per-instance descriptors could be interesting (that's why the > subject line caught my attention). > But your solution involves a custom __getattrib

Re: Per instance descriptors ?

2006-03-22 Thread Michael Spencer
Bruno Desthuilliers wrote: > Michael Spencer a écrit : >> I may be missing the subtlety of what you're up to, but why is >> overriding __getattribute__ more desirable than simply defining the >> descriptor in a subclass? > > The code snippet I gave as an example was not supposed to reflect how

Re: Per instance descriptors ?

2006-03-22 Thread Steven Bethard
bruno at modulix wrote: > Hi > > I'm currently playing with some (possibly weird...) code, and I'd have a > use for per-instance descriptors, ie (dummy code): > > class DummyDescriptor(object): > def __get__(self, obj, objtype=None): > if obj is None: > return self > return getatt

Re: Per instance descriptors ?

2006-03-22 Thread Bruno Desthuilliers
Michael Spencer a écrit : > bruno at modulix wrote: > >> Ziga Seilnacht wrote: >> >>> bruno at modulix wrote: >>> Hi I'm currently playing with some (possibly weird...) code, and I'd have a use for per-instance descriptors, ie (dummy code): >>> >>> >>> >>> Now the q

Re: Per instance descriptors ?

2006-03-22 Thread Michael Spencer
bruno at modulix wrote: > Ziga Seilnacht wrote: >> bruno at modulix wrote: >> >>> Hi >>> >>> I'm currently playing with some (possibly weird...) code, and I'd have a >>> use for per-instance descriptors, ie (dummy code): >> >> >> >>> Now the question: is there any obvious (or non-obvious) drawback

Re: Per instance descriptors ?

2006-03-22 Thread bruno at modulix
Ziga Seilnacht wrote: > bruno at modulix wrote: > >>Hi >> >>I'm currently playing with some (possibly weird...) code, and I'd have a >>use for per-instance descriptors, ie (dummy code): > > > > >>Now the question: is there any obvious (or non-obvious) drawback with >>this approach ? > > > St

Re: Per instance descriptors ?

2006-03-22 Thread Ziga Seilnacht
bruno at modulix wrote: > Hi > > I'm currently playing with some (possibly weird...) code, and I'd have a > use for per-instance descriptors, ie (dummy code): > Now the question: is there any obvious (or non-obvious) drawback with > this approach ? Staticmethods won't work anymore: >>> class