|
With the following (contrived) metaclass sample, I get a
NotImplementedError on the indicated line. It appears to be due to
IPythonContainer interface members being unimplemented in
IronPython.Runtime.ReflectedType. I’ve attached the .Net stack separately
as it was a little ugly. #######Begin Code Block 1 ####### #!/usr/bin/env python class DataType(type): def __init__(cls,
name, bases, dct): dct = dict([(k,
cls.make_prop(cls, k, v)) for k, v in dct.iteritems()]) type.__init__(cls,
name, bases, dct) def make_prop(cls,
name, type, read_only=False): prop_name =
'_%s__%s' % (cls.__name__, name) def setter(self,
__x): setattr(self,
prop_name, type(__x)) def
getter(self): return
getattr(self, prop_name) if read_only: ##
Error occurs here. return
property(getter) else: return
property(getter, setter) class Test(object): __metaclass__ =
DataType foo = str bar = int t = Test() t.foo = 'Hello World' t.bar = 42 print '%s: %d' % (t.foo,
t.bar) #######End Code Block 1 ####### IronPython stack: File …\metatest.py, line 23, in Initialize File …\metatest.py, line 6, in __init__ File …\metatest.py, line 18, in make_prop NotImplementedError: The method or operation is not
implemented. CPython output: Hello World: 42
#######Begin Code Block 2 ####### #!/usr/bin/env python class DataType(type): def __init__(cls,
name, bases, dct): dct = dict([(k,
cls.make_prop(cls, k, v)) for k, v in dct.iteritems()]) type.__init__(cls,
name, bases, dct) def make_prop(cls,
name, type, read_only=False): prop_name =
'_%s__%s' % (cls.__name__, name) def setter(self,
__x): setattr(self,
prop_name, type(__x)) def
getter(self): return
getattr(self, prop_name) return
property(getter, setter) class Test(object): __metaclass__ = DataType foo = str bar = int t = Test() t.foo = 'Hello World' t.bar = 42 print '%s: %d' % (t.foo,
t.bar) #######End Code Block 2####### Output: Hello World: 42 I’ve not yet had a chance to take a crack at a patch,
but I wanted to bring this up as soon as possible. Thanks, as always, for all your hard work, guys. -Nathan Ernst |
> IronPython.dll!IronPython.Runtime.ReflectedType.GetLength() Line 968 +
> 0x1d bytes C#
IronPython.dll!IronPython.Runtime.Converter.TryConvertToBoolean(object
value = {<type 'str'>}, out IronPython.Runtime.Conversion conversion = Eval)
Line 306 + 0x15 bytes C#
IronPython.dll!IronPython.Runtime.Converter.ConvertToBoolean(object
value = {<type 'str'>}) Line 1194 + 0xa bytes C#
IronPython.dll!IronPython.Runtime.Ops.IsTrue(object o = {<type 'str'>})
Line 93 + 0x7 bytes C#
[External Code]
IronPython.dll!IronPython.Runtime.Function4.Call(object arg0 =
UserType: "<class '<unknown>.Test'>", object arg1 = UserType: "<class
'<unknown>.Test'>", object arg2 = "foo", object arg3 = {<type 'str'>}) Line 288
+ 0x18 bytes C#
IronPython.dll!IronPython.Runtime.Method.Call(object arg0 = UserType:
"<class '<unknown>.Test'>", object arg1 = "foo", object arg2 = {<type 'str'>})
Line 463 + 0x2b bytes C#
IronPython.dll!IronPython.Runtime.Ops.CallWithContext(IronPython.Runtime.ICallerContext
context = {'__doc__': None, '__init__': <function __init__ at
0x000000000000002B>, 'make_prop': <function make_prop at 0x000000000000002C>},
object func = {<bound method DataType.make_prop of <class '<unknown>.Test'>>},
object arg0 = UserType: "<class '<unknown>.Test'>", object arg1 = "foo", object
arg2 = {<type 'str'>}) Line 155 + 0x22 bytes C#
[External Code]
IronPython.dll!IronPython.Runtime.Function4.Call(object arg0 =
UserType: "<class '<unknown>.Test'>", object arg1 = "Test", object arg2 =
{(<type 'object'>,)}, object arg3 = {'__doc__': None, '__metaclass__': <class
'__main__.DataType'>, 'foo': <type 'str'>, 'bar': <type 'int'>}) Line 288 +
0x18 bytes C#
IronPython.dll!IronPython.Runtime.Function4.Call(object[] args =
{Dimensions:[4]}) Line 296 + 0x48 bytes C#
IronPython.dll!IronPython.Runtime.Ops.Call(object func = {<function
__init__ at 0x000000000000002B>}, object[] args = {Dimensions:[4]}) Line 1126 +
0x1e bytes C#
IronPython.dll!IronPython.Runtime.Method.Call(object[] args =
{Dimensions:[3]}) Line 875 + 0x19 bytes C#
IronPython.dll!IronPython.Runtime.Ops.Call(object func = {<bound method
DataType.__init__ of <class '<unknown>.Test'>>}, object[] args =
{Dimensions:[3]}) Line 1126 + 0x1e bytes C#
IronPython.dll!IronPython.Runtime.UserType.Call(object[] args =
{Dimensions:[3]}) Line 369 + 0xa bytes C#
IronPython.dll!IronPython.Runtime.Ops.MakeClass(string mod =
"__main__", string name = "Test", IronPython.Runtime.Tuple bases = {(<type
'object'>,)}, System.Collections.Generic.IDictionary<object,object> vars =
{'__doc__': None, '__metaclass__': <class '__main__.DataType'>, 'foo': <type
'str'>, 'bar': <type 'int'>}) Line 1655 + 0x6b bytes C#
[External Code]
IronPython.dll!IronPython.Runtime.FrameCode.Run(IronPython.Runtime.Frame frame
= {IronPython.Runtime.Frame}) Line 189 + 0xd bytes C#
IronPython.dll!IronPython.Runtime.FunctionCode.Call(IronPython.Runtime.Frame
curFrame = {IronPython.Runtime.Frame}) Line 196 + 0xd bytes C#
IronPython.dll!IronPython.Runtime.Ops.Exec(IronPython.Runtime.ICallerContext
context = {IronPython.Runtime.Frame}, object code =
{IronPython.Runtime.FunctionCode},
System.Collections.Generic.IDictionary<object,object> locals = {'__name__':
'__main__', '__builtins__': <type 'Builtin'>, 'site': <module site from
"D:\Documents and
Settings\ernstn\Desktop\IronPython-1.0-Beta5\IronPython-1.0-Beta5\Lib\site.py">,
'__doc__': None, 'f': <file 'D:\documents and
settings\ernstn\desktop\metatest.py', r>, 'DataType': <class
'__main__.DataType'>}, System.Collections.Generic.IDictionary<object,object>
globals = {'__name__': '__main__', '__builtins__': <type 'Builtin'>, 'site':
<module site from "D:\Documents and
Settings\ernstn\Desktop\IronPython-1.0-Beta5\IronPython-1.0-Beta5\Lib\site.py">,
'__doc__': None, 'f': <file 'D:\documents and
settings\ernstn\desktop\metatest.py', r>, 'DataType': <class
'__main__.DataType'>}) Line 1718 + 0x3d bytes C#
IronPython.dll!IronPython.Runtime.Ops.Exec(IronPython.Runtime.ICallerContext
context = {IronPython.Runtime.Frame}, object code = {<file 'D:\documents and
settings\ernstn\desktop\metatest.py', r>}) Line 1683 + 0xf bytes C#
[External Code]
IronPython.dll!IronPython.Runtime.FrameCode.Run(IronPython.Runtime.Frame frame
= {IronPython.Runtime.Frame}) Line 189 + 0xd bytes C#
IronPython.dll!IronPython.Hosting.PythonEngine.DoOneInteractive(IronPython.Runtime.Frame
topFrame = {IronPython.Runtime.Frame}) Line 450 + 0xd bytes C#
IronPython.dll!IronPython.Hosting.PythonEngine.RunInteractiveLoop.AnonymousMethod(out
bool continueInteractionArgument = false) Line 356 + 0xd bytes C#
IronPython.dll!IronPython.Hosting.PythonEngine.TryInteractiveAction(IronPython.Hosting.PythonEngine.InteractiveAction
interactiveAction = {IronPython.Hosting.PythonEngine.InteractiveAction}, out
bool continueInteraction = false) Line 329 + 0xe bytes C#
IronPython.dll!IronPython.Hosting.PythonEngine.RunInteractiveLoop()
Line 354 + 0x36 bytes C#
IronPython.dll!IronPython.Hosting.PythonEngine.RunInteractive() Line
313 + 0x7 bytes C#
IronPythonConsole.exe!IronPythonConsole.PythonCommandLine.RunInteractive(IronPython.Hosting.PythonEngine
engine = {IronPython.Hosting.PythonEngine}) Line 398 + 0x9 bytes C#
IronPythonConsole.exe!IronPythonConsole.PythonCommandLine.Run(System.Collections.ArrayList
args = Count = 0, IronPython.Hosting.PythonEngine engine =
{IronPython.Hosting.PythonEngine}) Line 115 + 0x8 bytes C#
IronPythonConsole.exe!IronPythonConsole.PythonCommandLine.Main(string[]
rawArgs = {Dimensions:[0]}) Line 103 + 0xb bytes C#
[External Code]
_______________________________________________ users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
