concepts.dsl.dsl_functions.FunctionType#

class FunctionType[source]#

Bases: TypeBase

FunctionType defines the signature of a function.

Methods

assignment_type()

Return the value type for assignment.

downcast_compatible(other[, ...])

Check if the type is downcast-compatible with the other type; that is, if this type is a subtype of the other type.

from_annotation(function[, sig])

Create a FunctionType from a function annotation.

long_str()

Return the long string representation of the type.

resolve_args(*args, **kwargs)

Resolve the arguments to the function type.

set_parent_type(parent_type)

short_str()

Return the short string representation of the type.

unwrap_alias()

Attributes

alias

An optional alias of the type.

arguments_name2index

The mapping from argument names to argument indices.

base_typename

Return the typename of the base type.

element_type

The element type of the type.

is_batched_list_type

Return whether the type is a multidimensional list type.

is_list_type

Return whether the type is a list type.

is_object_type

Return whether the type is an object type.

is_pyobj_value_type

Return whether the type is a Python object value type.

is_scalar_value_type

is_sequence_type

Return whether the type is a sequence type.

is_tensor_value_type

Return whether the type is a tensor value type.

is_tuple_type

Return whether the type is a tuple type.

is_uniform_sequence_type

is_value_type

Return whether the type is a value type.

is_vector_value_type

is_wrapped_value_type

nr_arguments

Return the number of arguments.

nr_constant_arguments

nr_object_arguments

nr_value_arguments

nr_variable_arguments

parent_type

The parent type of the type.

parent_typename

Return the typename of the parent type.

typename

The (full) typename of the type.

argument_types

The types of the arguments.

argument_names

The names of the arguments.

arguments

The argument list composed of Variable instances.

arguments_dict

The arguments as a dict, as mappings from argument names to argument types.

return_type

The return type of the function type.

return_name

The name of the return value.

is_generator_function

Whether the function is a generator function.

is_simple_arguments

Whether all arguments are not batched-list types.

is_singular_return

Whether there is only one return value.

is_cacheable

Whether the function is cacheable.

__init__(arguments, return_type, argument_names=None, return_name=None, is_generator_function=False, alias=None)[source]#

Initialize the function type.

There are four ways to specify the arguments of the function type:

  1. A list of types, in which case the name of each argument is the index of the argument, using the format #{index}.

  2. A list of types as the arguments, and a list of names as the argument_names.

  3. A list of variables, in which case the name of each argument is the name of the variable.

  4. A dictionary of {name: type}, in which case the order of the arguments is the order of the keys.

The return type can be either a single type or a tuple of types (multi-return types).

Parameters:
__new__(**kwargs)#
assignment_type()#

Return the value type for assignment.

Return type:

TypeBase

downcast_compatible(other, allow_self_list=False, allow_list=False)#

Check if the type is downcast-compatible with the other type; that is, if this type is a subtype of the other type.

Parameters:
  • other (TypeBase) – the other type.

  • allow_self_list (bool) – if True, this type can be a list type derived from the other type.

  • allow_list (bool) – if True, the other type can be a list type derived from the type.

Return type:

bool

classmethod from_annotation(function, sig=None)[source]#

Create a FunctionType from a function annotation.

Parameters:
  • function (Callable) – The function.

  • sig (Signature | None) – The signature of the function.

Returns:

The function type.

Return type:

Union[FunctionType, OverloadedFunctionType]

long_str()#

Return the long string representation of the type.

Return type:

str

resolve_args(*args, **kwargs)[source]#

Resolve the arguments to the function type.

If you want to specify a specific “positional” argument by its index, use _{index} as the name of the argument.

Parameters:
  • *args (Any) – The positional arguments.

  • **kwargs (Any) – The keyword arguments.

Returns:

A list of argument values.

Return type:

List[Any]

set_parent_type(parent_type)#
Parameters:

parent_type (TypeBase)

short_str()#

Return the short string representation of the type.

Return type:

str

unwrap_alias()#
property alias: str | None#

An optional alias of the type.

argument_names: Tuple[str, ...]#

The names of the arguments.

argument_types: Tuple[ObjectType | ValueType | FunctionType | SequenceType, ...]#

The types of the arguments.

arguments: Tuple[Variable, ...]#

The argument list composed of Variable instances.

arguments_dict: Dict[str, ObjectType | ValueType | FunctionType | SequenceType]#

The arguments as a dict, as mappings from argument names to argument types.

property arguments_name2index#

The mapping from argument names to argument indices.

property base_typename#

Return the typename of the base type.

property element_type: TypeBase | None#

The element type of the type.

property is_batched_list_type: bool#

Return whether the type is a multidimensional list type.

is_cacheable: bool#

Whether the function is cacheable.

is_generator_function: bool#

Whether the function is a generator function.

property is_list_type: bool#

Return whether the type is a list type.

property is_object_type: bool#

Return whether the type is an object type.

property is_pyobj_value_type: bool#

Return whether the type is a Python object value type.

property is_scalar_value_type: bool#
property is_sequence_type: bool#

Return whether the type is a sequence type.

is_simple_arguments: bool#

Whether all arguments are not batched-list types.

is_singular_return: bool#

Whether there is only one return value.

property is_tensor_value_type: bool#

Return whether the type is a tensor value type.

property is_tuple_type: bool#

Return whether the type is a tuple type.

property is_uniform_sequence_type: bool#
property is_value_type: bool#

Return whether the type is a value type.

property is_vector_value_type: bool#
property is_wrapped_value_type: bool#
property nr_arguments: int#

Return the number of arguments.

property nr_constant_arguments#
property nr_object_arguments#
property nr_value_arguments#
property nr_variable_arguments#
property parent_type: TypeBase | None#

The parent type of the type.

property parent_typename#

Return the typename of the parent type.

return_name: str | Tuple[str, ...] | None#

The name of the return value.

return_type: ObjectType | ValueType | FunctionType | SequenceType#

The return type of the function type.

property typename: str#

The (full) typename of the type.