Overriding constructors for classes inheriting from Java
Offen
@timfel arbeitet bereits daran.
Seit 20.1.2025.
- Vorherrschende Sprache
- Python
- Sterne
- 1.6k
- Forks
- 155
- Ø Merge
- 9 Std. 42 Min.
- Gemergte PRs (30 T.)
- 36
Beschreibung
As of the latest version (23.1.0), GraalPy does not support overriding constructors for Python classes that inherit from Java.
The example below throws an error when we try to create a custom Exception wrapper in Python:
package my.pack;
import org.graalvm.polyglot.Value;
import org.graalvm.polyglot.Context;
public class Main {
static Context context = Context.newBuilder().allowAllAccess(true).build();
static Value clz;
public static void main(String[] args) {
context.eval("python", """
import java
class ParseException(java.lang.Exception):
def __init__(self, message):
self.__super__(message)
""");
clz = context.getBindings("python").getMember("ParseException");
Value obj = clz.newInstance("Hello from Java");
}
}
Result
// error
Exception in thread "main" TypeError: ParseException.__init__() missing 1 required positional argument: 'message'
at org.graalvm.sdk/org.graalvm.polyglot.Value.newInstance(Value.java:933)
at my.pack.Main.main(Main.java:18)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.