Skip to main content

Mojo function

check_and_get_or_convert_arg

check_and_get_or_convert_arg[T: ConvertibleFromPython](func_name: StringSlice[StaticConstantOrigin], py_args: PythonObject, index: Int) -> UnsafePointer[T]

Get the argument at the given index and convert it to a given Mojo type.

If the argument cannot be directly downcast to the given type, it will be converted to it.

Args:

  • func_name (StringSlice[StaticConstantOrigin]): The name of the function referenced in the error message if the downcast fails.
  • py_args (PythonObject): The Python tuple object containing the arguments.
  • index (Int): The index of the argument.

Returns:

A pointer to the Mojo value contained in or converted from the argument.

Raises:

If the argument cannot be downcast or converted to the given type.

Was this page helpful?