Class PositionalArguments
java.lang.Object
org.graalvm.python.embedding.PositionalArguments
Represents positional arguments (`*args`) in Python. The
PositionalArguments class provides a way to pass and manage a
variable number of positional arguments in a Java context, mimicking the
behavior of `*args` in Python. Instances of this class are immutable and can
be created using static factory methods for convenience.
Each PositionalArguments instance encapsulates an ordered list of
arguments, which can be of any type. These arguments are treated as if they
were passed to a Python function using the `*args` syntax.
Creating PositionalArguments
You can create an instance of PositionalArguments using one of the
provided static factory methods:
from(List): CreatesPositionalArgumentsfrom aListof arguments.of(Object...): CreatesPositionalArgumentsdirectly from a variable number of arguments.
Examples:
// Create PositionalArguments from a list
PositionalArguments args = PositionalArguments.from(List.of(1, "hello", true));
// Create PositionalArguments directly
PositionalArguments args2 = PositionalArguments.of(1, "hello", true);
When to Use
PositionalArguments should be used whenever a
Python function accepts variable-length positional arguments (i.e.,
*args). It can also be combined with KeywordArguments to
support functions that accept both types of arguments.
Important: An instance of PositionalArguments can be used in
one of the following scenarios:
- As the penultimate argument, followed by an instance of
KeywordArguments. - As the final argument, if the Python function does not accept named arguments.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic PositionalArgumentsCreates aPositionalArgumentsinstance from the specified list of values.static PositionalArgumentsCreates aPositionalArgumentsinstance from the specified values.
-
Method Details
-
of
Creates aPositionalArgumentsinstance from the specified values.- Parameters:
values- the positional arguments to be included; each value represents an argument passed to the Python function. Individual values can benull, which translates to the Python valueNone.- Returns:
- a new
PositionalArgumentsinstance containing the provided values
-
from
Creates aPositionalArgumentsinstance from the specified list of values.- Parameters:
values- a list of positional arguments to be included; each value represents an argument passed to the Python function. Null value can not be passed in this case.- Returns:
- a new
PositionalArgumentsinstance containing the provided values
-