From: <fwi...@us...> - 2006-06-08 02:44:11
|
Revision: 2802 Author: fwierzbicki Date: 2006-06-07 07:46:58 -0700 (Wed, 07 Jun 2006) ViewCVS: http://svn.sourceforge.net/jython/?rev=2802&view=rev Log Message: ----------- Some classmethod fixups, also added classmethod mro() to type. Modified Paths: -------------- trunk/jython/src/org/python/core/PyClassMethod.java trunk/jython/src/org/python/core/PyType.java trunk/sandbox/jt/classmethod.expose trunk/sandbox/jt/type.expose Modified: trunk/jython/src/org/python/core/PyClassMethod.java =================================================================== --- trunk/jython/src/org/python/core/PyClassMethod.java 2006-06-07 01:20:56 UTC (rev 2801) +++ trunk/jython/src/org/python/core/PyClassMethod.java 2006-06-07 14:46:58 UTC (rev 2802) @@ -35,8 +35,17 @@ return self.classmethod___get__(arg0,arg1); } + public PyObject __call__(PyObject arg0) { + return self.classmethod___get__(arg0); + } + + public PyObject inst_call(PyObject gself,PyObject arg0) { + PyClassMethod self=(PyClassMethod)gself; + return self.classmethod___get__(arg0); + } + } - dict.__setitem__("__get__",new PyMethodDescr("__get__",PyClassMethod.class,2,2,new exposed___get__(null,null))); + dict.__setitem__("__get__",new PyMethodDescr("__get__",PyClassMethod.class,1,2,new exposed___get__(null,null))); dict.__setitem__("__new__",new PyNewWrapper(PyClassMethod.class,"__new__",1,1) { public PyObject new_impl(boolean init,PyType subtype,PyObject[]args,String[]keywords) { @@ -56,10 +65,18 @@ this.callable = callable; } + public PyObject __get__(PyObject obj) { + return classmethod___get__(obj, null); + } + public PyObject __get__(PyObject obj, PyObject type) { return classmethod___get__(obj, type); } + final PyObject classmethod___get__(PyObject obj) { + return classmethod___get__(obj, null); + } + final PyObject classmethod___get__(PyObject obj, PyObject type) { if (type == null) type = obj.getType(); Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2006-06-07 01:20:56 UTC (rev 2801) +++ trunk/jython/src/org/python/core/PyType.java 2006-06-07 14:46:58 UTC (rev 2802) @@ -25,6 +25,43 @@ dict.__setitem__("__base__",new PyGetSetDescr("__base__",PyType.class,"getBase",null)); dict.__setitem__("__bases__",new PyGetSetDescr("__bases__",PyType.class,"getBases",null)); dict.__setitem__("__mro__",new PyGetSetDescr("__mro__",PyType.class,"getMro",null)); + class exposed_mro extends PyBuiltinFunctionNarrow { + + private PyType self; + + public PyObject getSelf() { + return self; + } + + exposed_mro(PyType self,PyBuiltinFunction.Info info) { + super(info); + this.self=self; + } + + public PyBuiltinFunction makeBound(PyObject self) { + return new exposed_mro((PyType)self,info); + } + + public PyObject __call__(PyObject arg0) { + return self.type_mro(arg0); + } + + public PyObject inst_call(PyObject gself,PyObject arg0) { + PyType self=(PyType)gself; + return self.type_mro(arg0); + } + + public PyObject __call__() { + return self.type_mro(); + } + + public PyObject inst_call(PyObject gself) { + PyType self=(PyType)gself; + return self.type_mro(); + } + + } + dict.__setitem__("mro", new PyClassMethod(new PyMethodDescr("mro",PyType.class,0,1,new exposed_mro(null,null)))); class exposed___getattribute__ extends PyBuiltinFunctionNarrow { private PyType self; @@ -468,7 +505,26 @@ System.out.println(new PyList(objs).toString()); } - final PyObject[] type_mro() { + + final PyTuple type_mro() { + return getMro(); + } + + final PyTuple type_mro(PyObject o) { + //FIXME: PyMethDescr should be gaurding against args that are not the + // correct type in the generated code, but that is not working. + // fix and delete this instanceof check. + if (!(o instanceof PyType)) { + throw Py.TypeError( + "descriptor 'mro' requires a 'type' object but received a '" + + o.getType().fastGetName() + + "'"); + } + PyType type = (PyType)o; + return type.type_mro(); + } + + final PyObject[] compute_mro() { PyObject[] bases = this.bases; int n = bases.length; for (int i=0; i < n; i++) { @@ -671,7 +727,7 @@ mro_meth = metatype.lookup("mro"); if (mro_meth == null) { - newmro = newtype.type_mro(); + newmro = newtype.compute_mro(); } else { newmro = Py.make_array(mro_meth.__get__(newtype,metatype).__call__()); } Modified: trunk/sandbox/jt/classmethod.expose =================================================================== --- trunk/sandbox/jt/classmethod.expose 2006-06-07 01:20:56 UTC (rev 2801) +++ trunk/sandbox/jt/classmethod.expose 2006-06-07 14:46:58 UTC (rev 2802) @@ -2,5 +2,5 @@ type_name: classmethod type_class: PyClassMethod # exposed methods -expose_meth: __get__ oo +expose_meth: __get__ oo? expose_new_immutable: 1 1 Modified: trunk/sandbox/jt/type.expose =================================================================== --- trunk/sandbox/jt/type.expose 2006-06-07 01:20:56 UTC (rev 2801) +++ trunk/sandbox/jt/type.expose 2006-06-07 14:46:58 UTC (rev 2802) @@ -8,7 +8,7 @@ expose_getset: __bases__ getBases expose_getset: __mro__ getMro # exposed methods -#expose_meth: :o mro o +expose_meth: :o mro o? expose_meth: __getattribute__ n{attribute name} String name = `arg0; PyObject ret = self.type___findattr__(name); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |