[IronPython] Descriptor/metaclass problems

Gary Stephenson garys at ihug.com.au
Fri Sep 15 01:55:55 CEST 2006


Hi,

The following code works perfectly in CPython, but is all over the shop in 
ipy :-(  Any ideas on how I might make it work in ipy?

class valueDescriptor(object):
    def __init__(self,x=None):
        self.value = x
    def __get__(self,ob,cls):
        return self.value
    def __set__(self,ob,x):
        self.value = x

class Ameta(type):
    def createShared( cls, nm, initValue=None ):
        o = valueDescriptor(initValue)
        setattr( cls,nm, o )
        setattr( cls.__class__,nm, o )

class A:
    __metaclass__ = Ameta

class B( A ):
    A.createShared("cls2",1)

def show():
    # all outputs should be the same!!
    print o.cls2
    print o2.cls2
    print A.cls2
    print B.cls2

o = A()
o2 = B()
show()

B.cls2 = 2
show()

A.cls2 = 3
show()

o.cls2 = 4
show()

o2.cls2 = 5
show()






More information about the Ironpython-users mailing list