'Jython code stopped working after upgrade from 2.7.1 to 2.7.2
// MyPythonObject.java
import org.python.core.PyObject;
import org.python.expose.ExposedClassMethod;
import org.python.expose.ExposedType;
@ExposedType
public class MyPythonObject extends PyObject {
@ExposedClassMethod
public void hello() {
System.out.println("Hello");
}
}
// Main.java
import org.python.core.PyStringMap;
import org.python.util.PythonInterpreter;
public class Main {
public static void main(String[] args) throws Exception {
PythonInterpreter.initialize(null, null, new String[0]);
PyStringMap map = new PyStringMap();
PythonInterpreter pythonInterpreter = new PythonInterpreter(map);
map.__setitem__("myobj", new MyPythonObject());
pythonInterpreter.exec("myobj.hello()");
}
}
The code runs fine on Jython 2.7.1 but fails on Jython 2.7.2:
Exception in thread "main" Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'null' object has no attribute 'hello'
Is this a bug in Jython 2.7.2?
P.S. I asked the same question on GitHub but didn't get any answer yet.
Solution 1:[1]
david.perez has asked the right question. The exposer annotations are used to create built-in Python objects in the interpreter. They add code to methods when processed during the Jython build, in classes that will act like a Python built-in.
You do not need them simply to use a class defined in Java from a program written in Python. Take them off and your code works.
I don't know what changed from 2.7.1 to move exposer annotations from unnecessary to harmful. (ASM update, maybe.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jeff Allen |