Overriding constructors for classes inheriting from Java
@timfel is already working on this.
Since Jan 20, 2025.
Assessment
This issue has not been assessed yet.
Description
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)
- Dominant language
- Python
- Stars
- 1.6k
- Forks
- 155
- Avg merge
- 8h 58m
- Merged PRs (30d)
- 39
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from oracle/graalpython
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
oracle/graalpython#1105 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
oracle/graalpython#1102 ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
oracle/graalpython#1157 · 1 assignee ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 74/100
oracle/graalpython#1133 ·
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 68/100
oracle/graalpython#1112 ·
All issues in oracle/graalpython
Similar issues
-
Add: hunch Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AbdelStark/awesome-typesafe#104 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
DiamondLightSource/dodal#2211 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
openml/openml-python#1749 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sipyourdrink-ltd/bernstein#6191 ·