Skip to content

Instantly share code, notes, and snippets.

@jimbaker
Created January 8, 2014 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimbaker/8319678 to your computer and use it in GitHub Desktop.
Save jimbaker/8319678 to your computer and use it in GitHub Desktop.
Jython trunk currently does not allow mixing together in the use of a metaclass Java classes/interfaces with Python types, even though both are new-style classes. Currently this gets a TypeError: Error when calling the metaclass bases (metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all …
diff -r b2890af7a5e8 src/org/python/core/PyType.java
--- a/src/org/python/core/PyType.java Thu Jan 02 16:25:39 2014 -0800
+++ b/src/org/python/core/PyType.java Wed Jan 08 09:31:55 2014 -0700
@@ -1119,6 +1119,10 @@
return best;
}
+ private static boolean isJavaRootClass(PyType type) {
+ return type instanceof PyJavaType && type.fastGetName().equals("java.lang.Class");
+ }
+
/**
* Finds the most derived subtype of initialMetatype in the types
* of bases, or initialMetatype if it is already the most derived.
@@ -1130,11 +1134,19 @@
*/
private static PyType findMostDerivedMetatype(PyObject[] bases_list, PyType initialMetatype) {
PyType winner = initialMetatype;
+ if (isJavaRootClass(winner)) { // consider this root class to be equivalent to type
+ winner = PyType.TYPE;
+ }
+
for (PyObject base : bases_list) {
if (base instanceof PyClass) {
continue;
}
PyType curtype = base.getType();
+ if (isJavaRootClass(curtype)) {
+ curtype = PyType.TYPE;
+ }
+
if (winner.isSubType(curtype)) {
continue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment