From: <pj...@us...> - 2009-10-26 06:37:03
|
Revision: 6903 http://jython.svn.sourceforge.net/jython/?rev=6903&view=rev Author: pjenvey Date: 2009-10-26 06:36:47 +0000 (Mon, 26 Oct 2009) Log Message: ----------- move Derived's dispatch__init__ guard into PyType and the rest of it into Deriveds Modified Paths: -------------- trunk/jython/src/org/python/core/Deriveds.java trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/PyType.java trunk/jython/src/org/python/modules/thread/PyLocal.java trunk/jython/src/templates/object.derived Modified: trunk/jython/src/org/python/core/Deriveds.java =================================================================== --- trunk/jython/src/org/python/core/Deriveds.java 2009-10-26 04:16:36 UTC (rev 6902) +++ trunk/jython/src/org/python/core/Deriveds.java 2009-10-26 06:36:47 UTC (rev 6903) @@ -10,6 +10,20 @@ private static final PyObject objectGetattribute = PyObject.TYPE.__findattr__("__getattribute__"); + public static void dispatch__init__(PyObject self, PyObject[] args, String[] keywords) { + PyType type = self.getType(); + PyObject init = type.lookup("__init__"); + if (init == null) { + return; + } + PyObject result = init.__get__(self, type).__call__(args, keywords); + if (result != Py.None) { + throw Py.TypeError(String.format("__init__() should return None, not '%.200s'", + result.getType().fastGetName())); + } + self.proxyInit(); + } + /** * Deriveds' __findattr_ex__ implementation. * Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2009-10-26 04:16:36 UTC (rev 6902) +++ trunk/jython/src/org/python/core/PyObject.java 2009-10-26 06:36:47 UTC (rev 6903) @@ -114,13 +114,14 @@ /** * Dispatch __init__ behavior */ - public void dispatch__init__(PyType type, PyObject[] args, String[] keywords) {} + public void dispatch__init__(PyObject[] args, String[] keywords) { + } /** * Attempts to automatically initialize our Java proxy if we have one and it wasn't initialized * by our __init__. */ - protected void proxyInit() { + void proxyInit() { Class<?> c = getType().getProxyType(); if (javaProxy != null || c == null) { return; Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-10-26 04:16:36 UTC (rev 6902) +++ trunk/jython/src/org/python/core/PyType.java 2009-10-26 06:36:47 UTC (rev 6903) @@ -1477,11 +1477,13 @@ } PyObject obj = invokeNew(new_, this, true, args, keywords); - // special case type(x) - if (this == TYPE && args.length == 1 && keywords.length == 0) { + // When the call was type(something) or the returned object is not an instance of + // type, it won't be initialized + if ((this == TYPE && args.length == 1 && keywords.length == 0) + || !obj.getType().isSubType(this)) { return obj; } - obj.dispatch__init__(this, args, keywords); + obj.dispatch__init__(args, keywords); return obj; } Modified: trunk/jython/src/org/python/modules/thread/PyLocal.java =================================================================== --- trunk/jython/src/org/python/modules/thread/PyLocal.java 2009-10-26 04:16:36 UTC (rev 6902) +++ trunk/jython/src/org/python/modules/thread/PyLocal.java 2009-10-26 06:36:47 UTC (rev 6903) @@ -81,7 +81,7 @@ if (ldict == null) { ldict = new PyDictionary(); tdict.set(ldict); - dispatch__init__(getType(), args, keywords); + dispatch__init__(args, keywords); } return ldict; } Modified: trunk/jython/src/templates/object.derived =================================================================== --- trunk/jython/src/templates/object.derived 2009-10-26 04:16:36 UTC (rev 6902) +++ trunk/jython/src/templates/object.derived 2009-10-26 06:36:47 UTC (rev 6903) @@ -385,19 +385,8 @@ return super.__pow__(other, modulo); } - public void dispatch__init__(PyType type,PyObject[] args,String[] keywords) { - PyType self_type = getType(); - if (self_type.isSubType(type)) { - PyObject impl = self_type.lookup("__init__"); - if (impl != null) { - PyObject res = impl.__get__(this,self_type).__call__(args,keywords); - if (res != Py.None) { - throw Py.TypeError(String.format("__init__() should return None, not '%.200s'", - res.getType().fastGetName())); - } - proxyInit(); - } - } + public void dispatch__init__(PyObject[] args, String[] keywords) { + Deriveds.dispatch__init__(this, args, keywords); } public PyObject __index__() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |