Message5608
If you create a hierarchy of Python classes that implement Java interfaces as shown below, jython will (incorrectly) emit the error:
class SpaceDog(HoundDog):
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases HoundDog[<class 'jytest.Dog'>, <type 'org.python.proxies.jytest$HoundDog$1'>]
Here is the test file which causes the error:
--------------------------------------------------------------
from java.lang import Runnable, Comparable
class Dog(Runnable):
def run(self):
print "I ran"
class HoundDog(Dog, Comparable):
def compareTo(self, o):
return 0
class SpaceDog(HoundDog):
pass
--------------------------------------------------------------
I spent some time walking through the debugger, and there seems to be something incorrect with the method PyType.computeMro() .. in particular, the following code snippet isn't working right; it adds the proxy object to the MRO list for HoundDog even though it is already in the list; having two classes in the MRO list for HoundDog is what causes SpaceDog to blow up with the MRO error.
if (!addedProxy && !(this instanceof PyJavaType) && candidate instanceof PyJavaType
&& candidate.javaProxy != null
&& PyProxy.class.isAssignableFrom(((Class<?>)candidate.javaProxy))
&& candidate.javaProxy != javaProxy) {
// If this is a subclass of a Python class that subclasses a Java class, slip the
// proxy for this class in before the proxy class in the superclass' mro.
// This exposes the methods from the proxy generated for this class in addition to
// those generated for the superclass while allowing methods from the superclass to
// remain visible from the proxies.
addedProxy = true;
mro.add(PyType.fromClass(((Class<?>)javaProxy)));
} |
|
Date |
User |
Action |
Args |
2010-03-29 20:14:08 | matt_brinkley | set | recipients:
+ matt_brinkley |
2010-03-29 20:14:08 | matt_brinkley | set | messageid: <1269893648.53.0.930151032187.issue1587@psf.upfronthosting.co.za> |
2010-03-29 20:14:08 | matt_brinkley | link | issue1587 messages |
2010-03-29 20:14:06 | matt_brinkley | create | |
|