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): # do some

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.value def

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): return self.value def __set__(self,

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 checking... only accept

per instance descriptors

2006-12-06 Thread Simon Bunker
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 floats etc self.value = val class

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 floats etc

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

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 floats etc

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 __getattribute__

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, key

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 with the

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

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'd

Re: Per instance descriptors ?

2006-03-23 Thread bruno at modulix
Steven Bethard wrote: (snip code) But that looks pretty nasty to me. aol / 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

Per instance descriptors ?

2006-03-22 Thread bruno at modulix
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 getattr(obj, 'bar', 'no bar') class MyClass1

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): snip Now the question: is there any obvious (or non-obvious) drawback with this approach ? Staticmethods won't work anymore: class Test

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): snip Now the question: is there any obvious (or non-obvious) drawback with this approach ? Staticmethods

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): snip Now the question: is there any obvious (or non-obvious) drawback with this approach

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): snip Now the question: is there any obvious (or non

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 getattr(obj

Re: Per instance descriptors ?

2006-03-22 Thread Michael Spencer
effectively mean to use per-instance descriptors, it was just a kind of Minimal Working Code (tm). The real life code is about 500 LOC, and explaining the whole thing would take far too long. Also, as I said, this is mostly syntactic sugar - there are simpler, less 'hackish' (but also less