TypeDef#

class hugr.ext.TypeDef(name: str, description: str, params: list[TypeParam], bound: ExplicitBound | FromParamsBound)[source]#

Bases: ExtensionObject

Type definition in an Extension.

Examples

>>> td = TypeDef(
...     name="MyType",
...     description="A type definition.",
...     params=[tys.TypeTypeParam(tys.Bool)],
...     bound=ExplicitBound(tys.TypeBound.Copyable),
... )
>>> td.name
'MyType'

Methods

get_extension

Retrieve the extension associated with the object.

instantiate

Instantiate a concrete type from this type definition.

Attributes

name

The name of the type.

description

A description of the type.

params

The type parameters of the type if polymorphic.

bound

The type bound of the type.

bound: ExplicitBound | FromParamsBound#

The type bound of the type.

description: str#

A description of the type.

get_extension() Extension#

Retrieve the extension associated with the object.

Returns:

The extension associated with the object.

Raises:

NoParentExtension – If the object is not associated with an extension.

instantiate(args: Sequence[tys.TypeArg]) tys.ExtType[source]#

Instantiate a concrete type from this type definition.

Parameters:

args – Type arguments corresponding to the type parameters of the definition.

name: str#

The name of the type.

params: list[TypeParam]#

The type parameters of the type if polymorphic.