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
[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
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,
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
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
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
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
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
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__
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
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
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
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
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
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
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
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
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
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
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
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
21 matches
Mail list logo