Class PythonInvocation
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.graalvm.polyglot.ValuebindPythonDescriptor(org.graalvm.polyglot.Value descriptor, Object receiver, org.graalvm.polyglot.Value owner) Bind a raw Python descriptor to a receiver when the descriptor protocol is available.static @Nullable org.graalvm.polyglot.ValuegetRawClassMember(org.graalvm.polyglot.Value pythonClass, String name) Read a Python class member directly from the MRO dictionaries, bypassing descriptor binding.static org.graalvm.polyglot.ValueinvokeIntroducedMethod(org.graalvm.polyglot.Value receiver, String name, Class<?> returnType, Object @Nullable [] arguments) Invoke a method that an introduction advice adds to a Python class through the interfaces of its@Introduction.static org.graalvm.polyglot.ValueinvokePythonMethod(org.graalvm.polyglot.Value receiver, String name, Object @Nullable [] arguments) Invoke a generated bridge method on a Python receiver.static Object[]withVarargs(Object[] arguments, @Nullable Object varargs) Spread a Java varargs array into the positional arguments of a Python call.
-
Method Details
-
invokePythonMethod
public static org.graalvm.polyglot.Value invokePythonMethod(org.graalvm.polyglot.Value receiver, String name, Object @Nullable [] arguments) Invoke a generated bridge method on a Python receiver.Generated Java stubs use this method instead of calling
Value.invokeMember(String, Object...)directly so every Python call enters thePythonContextRuntimeexecution tracker for the receiver's actual context. The execution frame keeps graceful shutdown and pooled-context cleanup from observing the context as idle while a bridge invocation, or nested bridge invocation, is still unwinding.Invocation is delegated to a context-local Python helper because Python method lookup is not just a map lookup. The helper first uses
getattrfor normal bound-method behavior, then falls back to walking the class__mro__and applying__get__so descriptors and inherited methods are invoked with Python semantics before the result crosses back to Java.- Parameters:
receiver- The Python receivername- The method namearguments- The method arguments, ornullfor none- Returns:
- The invocation result
-
withVarargs
Spread a Java varargs array into the positional arguments of a Python call.A Python
*argsparameter is bridged as a trailing Java array. Python expects the elements as separate positional arguments, so the generated bridge appends them to the fixed arguments instead of passing the array as a single argument.- Parameters:
arguments- The fixed argumentsvarargs- The varargs array, ornullfor no additional arguments- Returns:
- The positional arguments of the Python call
-
invokeIntroducedMethod
public static org.graalvm.polyglot.Value invokeIntroducedMethod(org.graalvm.polyglot.Value receiver, String name, Class<?> returnType, Object @Nullable [] arguments) Invoke a method that an introduction advice adds to a Python class through the interfaces of its@Introduction. The proxy of the class carries such a method as a Python member; an instance that is not the proxy (an entity instantiated by JPA, a value created from Java) has no member of that name and, as in Java where only the proxy class implements the introduced interface, no implementation for it: the result is thenNonewhen the method returns a reference or nothing. A method returning a primitive has no value to answer without an implementation, so the missing member is reported instead of surfacing later as a failed conversion ofNone.- Parameters:
receiver- The Python receivername- The method namereturnType- The declared return type of the introduced methodarguments- The method arguments, ornullfor none- Returns:
- The invocation result, or
Noneif the receiver has no such member - Throws:
IllegalStateException- If the receiver has no such member and the method returns a primitive
-
getRawClassMember
public static @Nullable org.graalvm.polyglot.Value getRawClassMember(org.graalvm.polyglot.Value pythonClass, String name) Read a Python class member directly from the MRO dictionaries, bypassing descriptor binding.- Parameters:
pythonClass- The Python classname- The member name- Returns:
- The raw member, or null if none exists
-
bindPythonDescriptor
public static org.graalvm.polyglot.Value bindPythonDescriptor(org.graalvm.polyglot.Value descriptor, Object receiver, org.graalvm.polyglot.Value owner) Bind a raw Python descriptor to a receiver when the descriptor protocol is available.- Parameters:
descriptor- The raw descriptorreceiver- The receiver objectowner- The owner class- Returns:
- The bound descriptor, or the original descriptor if it cannot be bound
-