[IronPython] Descriptor/metaclass problems
Martin Maly
Martin.Maly at microsoft.com
Fri Sep 15 17:25:35 CEST 2006
Filed as CodePlex issue # 3287
-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Gary Stephenson
Sent: Thursday, September 14, 2006 4:56 PM
To: Discussion of IronPython
Subject: [IronPython] Descriptor/metaclass problems
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()
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
More information about the Ironpython-users
mailing list