-
Notifications
You must be signed in to change notification settings - Fork 226
Description
I'm trying to use custom class implementing Set and Comparable interface in Jython but have the following error :
Exception in thread "main" TypeError: Supertypes that share a modified attribute have an MRO conflict[attribute=__le__, supertypes=[<type 'java.util.Set'>], type=Scratch$MyCollection]
I am using java temurin 21.0.6 and jython-standalone 2.7.4.
I prepared a simple code example to reproduce :
public static void main(String[] args) {
try (PythonInterpreter interpreter = new PythonInterpreter()) {
interpreter.set("c", new MyCollection());
}
}(Please note that you can just use Py.java2py(new MyCollection()) and will achieve the same result)
Where MyCollection is a basic implementation :
private static class MyCollection implements Set, Comparable {
@Override
public int compareTo(@NotNull Object o) {
return 0;
}
@Override
public int size() {
return 0;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean contains(Object o) {
return false;
}
@Override
public @NotNull Iterator iterator() {
return null;
}
@Override
public @NotNull Object[] toArray() {
return new Object[0];
}
@Override
public boolean add(Object o) {
return false;
}
@Override
public boolean remove(Object o) {
return false;
}
@Override
public boolean addAll(@NotNull Collection c) {
return false;
}
@Override
public void clear() {
}
@Override
public boolean removeAll(@NotNull Collection c) {
return false;
}
@Override
public boolean retainAll(@NotNull Collection c) {
return false;
}
@Override
public boolean containsAll(@NotNull Collection c) {
return false;
}
@Override
public @NotNull Object[] toArray(@NotNull Object[] a) {
return new Object[0];
}
}Also, I tried in previous version 2.7.3 to 2.7.0 this even simpler code and has a similar error yet not the same :
public static void main(String[] args) {
try (PythonInterpreter interpreter = new PythonInterpreter()) {
interpreter.set("c", new TreeSet<>());
}
}Exception in thread "main" TypeError: Supertypes that share a modified attribute have an MRO conflict[attribute=remove, supertypes=[<type 'java.util.SequencedSet'>, <type 'java.util.Set'>], type=SortedSet]
I tried to look a bit into it but failed to grasp exactly what is wrong, I feel like the PyJavaType.bases field is the key here, it's an array and from what I see, the order of the element inside it determine if the MRO will crash or not.