Skip to content

Commit 2c3046e

Browse files
committed
Add missing call to __init__, since Java subclasses' __new__ returns a non-subinstance
1 parent 8331a23 commit 2c3046e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_interop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ class PythonLevel(Level, new_style=True):
14231423
def __new__(cls, name="default name", level=2):
14241424
return super().__new__(cls, name, level)
14251425

1426-
def __init__(self):
1426+
def __init__(self, *args, **kwarg):
14271427
self.misc_value = 42
14281428

14291429
def getName(self):

graalpython/lib-graalpython/__graalpython__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ def __delattr__(self, name):
204204
polyglot.register_interop_type(JavaClass, MroClass, allow_method_overwrites=True)
205205

206206
# A class to make sure that the returned Python class can be used for
207-
# issubclass and isinstance checks with the Java instances
207+
# issubclass and isinstance checks with the Java instances, and to wrap all
208+
# methods in created subclasses to provide the proper `self` (the Java
209+
# instance) and still make `super()` work.
208210
class JavaSubclassMeta(type):
209211
@property
210212
def __bases__(self):
@@ -274,6 +276,7 @@ def __new__(cls, *args, **kwds):
274276
delegate = object.__new__(cls)
275277
java_object = polyglot.__new__(JavaClass, *(args + (delegate,)))
276278
delegate.__this__ = java_object
279+
delegate.__init__(*args, **kwds)
277280
return java_object
278281

279282
return type(name, (DelegateSuperclass,), ns)

0 commit comments

Comments
 (0)