pyccel.ast.type_annotations module#

Module containing all classes useful for type annotation.

class pyccel.ast.type_annotations.FunctionTypeAnnotation(args, result, is_const=True)[source]#

Bases: PyccelAstNode

A class which describes a type annotation on a function address.

A class which stores all information necessary to describe the prototype of the function being referenced. This includes the type annotations for the arguments and the results.

Parameters:
  • args (list of SyntacticTypeAnnotation | UnionTypeAnnotation) – The type annotations describing the arguments of the function address. In the syntactic stage these objects are of type SyntacticTypeAnnotation. In the semantic stage these objects are of type UnionTypeAnnotation.

  • result (SyntacticTypeAnnotation | UnionTypeAnnotation) – The type annotation describing the result of the function address. In the syntactic stage this object is of type SyntacticTypeAnnotation. In the semantic stage this object is of type UnionTypeAnnotation.

  • is_const (bool, default=True) – True if the function pointer cannot be modified, false otherwise.

property args#

Get the type annotations describing the arguments of the function address.

Get the type annotations describing the arguments of the function address. In the syntactic stage these objects are of type SyntacticTypeAnnotation. In the semantic stage these objects are of type UnionTypeAnnotation.

property is_const#

Indicates whether the object will remain constant.

Returns a boolean which is false if the value of the object can be modified, and true otherwise.

property result#

Get the type annotation describing the result of the function address.

Get the type annotation describing the result of the function address. In the syntactic stage this object is of type SyntacticTypeAnnotation. In the semantic stage this object is of type UnionTypeAnnotation.

class pyccel.ast.type_annotations.SyntacticTypeAnnotation(dtype=None, order=None)[source]#

Bases: PyccelAstNode

A class describing the type annotation parsed in the syntactic stage.

A class which holds all the type information parsed from literal string annotations in the syntactic stage. Annotations can describe multiple different possible types. This function stores lists of the critical properties.

Parameters:
  • dtype (str | IndexedElement | DottedName) – The dtype named in the type annotation.

  • order (str | None) – The order requested in the type annotation.

property dtype#

A list of the dtypes named in the type annotation.

A list of the dtypes named in the type annotation. These dtypes are all strings.

property order#

A list of the orders requested for each possible annotation.

A list of strings or None values indicating the order of the generated object.

class pyccel.ast.type_annotations.UnionTypeAnnotation(*type_annotations)[source]#

Bases: PyccelAstNode

A class which holds multiple possible type annotations.

A class which holds multiple possible type annotations.

Parameters:

*type_annotations (tuple of VariableTypeAnnotation | FunctionTypeAnnotation) – The objects describing the possible type annotations.

add_type(annot)[source]#

Add an additional type to the type annotations.

Add an additional type to the type annotations stored in this UnionTypeAnnotation.

Parameters:

annot (VariableTypeAnnotation | FunctionTypeAnnotation) – The object describing the additional type annotation.

property type_list#

Get the list of possible type annotations.

Get the list of possible type annotations (stored in a tuple).

class pyccel.ast.type_annotations.VariableTypeAnnotation(class_type: PyccelType, is_const: bool = False)[source]#

Bases: PyccelAstNode

A class which describes a type annotation on a variable.

A class which stores all information which may be provided in a type annotation in order to declare a variable.

Parameters:
  • class_type (PyccelType) – The requested Python type of the variable.

  • is_const (bool, default=False) – True if the variable cannot be modified, false otherwise.

property class_type#

Get the Python type of the object.

The Python type of the object. In the case of scalars this is equivalent to the datatype. For objects in (homogeneous) containers (e.g. list/ndarray/tuple), this is the type of the container.

property is_const#

Indicates whether the object will remain constant.

Returns a boolean which is false if the value of the object can be modified, and true otherwise.

property rank#

Number of dimensions of the object.

Number of dimensions of the object. If the object is a scalar then this is equal to 0.