concepts.dsl.dsl_functions.FunctionType#

class FunctionType[source]#

Bases: TypeBase

FunctionType defines the signature of a function.

Methods

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.

short_str()

Return the short string representation of the type.

Attributes

alias

An optional alias of the type.

arguments_name2index

The mapping from argument names to argument indices.

is_list_type

Return whether the type is a list 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_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, 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)#
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]

short_str()#

Return the short string representation of the type.

Return type:

str

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, ...]#

The types of the arguments.

arguments: Tuple[Variable, ...]#

The argument list composed of Variable instances.

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

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

property arguments_name2index#

The mapping from argument names to argument indices.

is_cacheable: bool#

Whether the function is cacheable.

property is_list_type#

Return whether the type is a list type.

is_singular_return: bool#

Whether there is only one return value.

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: ValueType | ListType | FunctionType | Sequence[ValueType | ListType | FunctionType] | Tuple[ValueType | ListType | FunctionType | Sequence[ValueType | ListType | FunctionType], ...]#

The return type of the function type.

property typename: str#

The (full) typename of the type.