From: Phillip J. E. <pj...@te...> - 2001-07-15 16:39:12
|
At 03:42 AM 7/15/01 +0200, Samuele Pedroni wrote: >So after the trouble of a few posts and of making me propose a bad and not >working hack, you came out >with some actual code <wink>. I could've proposed code to start with, but as you can see, my Java isn't as good as my Python. :) Here's a version of your patch that works with my minimal ExtensionClass emulation: ? org/python/util/PyMetaClass.java Index: org/python/core/Py.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/Py.java,v retrieving revision 2.46 diff -u -r2.46 Py.java --- org/python/core/Py.java 2001/07/03 20:20:27 2.46 +++ org/python/core/Py.java 2001/07/15 14:18:27 @@ -1406,6 +1406,10 @@ } + private static Class[] pyClassCtrSignature = + {String.class,PyTuple.class,PyObject.class,Class.class}; + + public static PyObject makeClass(String name, PyObject[] bases, PyCode code, PyObject doc, Class proxyClass,PyObject[] closure_cells) @@ -1419,6 +1423,14 @@ dict.__setitem__("__doc__", doc); for (int i=0; i<bases.length; i++) { + if (bases[i] instanceof org.python.util.PyMetaClass) { + try { + return (PyObject)bases[i].getClass().getConstructor(pyClass CtrSignature).newInstance( + new Object[] { name, new PyTuple(bases), dict, proxyClass }); + } catch (Exception e) { + throw Py.TypeError("meta-class fails to supply proper ctr:"+bases[i].safeRepr()); + } + } if (!(bases[i] instanceof PyClass)) { PyObject c = bases[i].__class__; // Only try the meta-class trick on __class__'s that are It's the same as yours, except that it goes before the PyClass check, so that an object that "extends PyClass implements PyMetaClass" will be treated as a metaclass. >plus an empty org.python.util.PyMetaClass interface >could make into the code, no problem with that. Thanks! This will be a big help for my project, as now I'll be able to use ComputedAttributes in TransWarp without having to worry about there being no way to do them in Jython. |