Class PositionalArguments

java.lang.Object
org.graalvm.python.embedding.PositionalArguments

public abstract sealed class PositionalArguments extends Object
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): Creates PositionalArguments from a List of arguments.
  • of(Object...): Creates PositionalArguments directly 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.
This ensures proper alignment with Python's argument structure and guarantees that all arguments are passed correctly.
See Also:
  • Method Details

    • of

      public static PositionalArguments of(Object... values)
      Creates a PositionalArguments instance 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 be null, which translates to the Python value None.
      Returns:
      a new PositionalArguments instance containing the provided values
    • from

      public static PositionalArguments from(List<Object> values)
      Creates a PositionalArguments instance 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 PositionalArguments instance containing the provided values