Skip to content

Commit 36548ab

Browse files
authored
feat: instantiate method for OpDef (#1576)
Closes #1512 drive-by: typos
1 parent f8bf61a commit 36548ab

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

hugr-py/src/hugr/ext.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,20 @@ def qualified_name(self) -> str:
218218
return f"{ext_name}.{self.name}"
219219
return self.name
220220

221+
def instantiate(
222+
self,
223+
args: Sequence[tys.TypeArg] | None = None,
224+
concrete_signature: tys.FunctionType | None = None,
225+
) -> ops.ExtOp:
226+
"""Instantiate an operation from this definition.
227+
228+
Args:
229+
args: Type arguments corresponding to the type parameters of the definition.
230+
concrete_signature: Concrete function type of the operation, only required
231+
if the operation is polymorphic.
232+
"""
233+
return ops.ExtOp(self, concrete_signature, list(args or []))
234+
221235

222236
@dataclass
223237
class ExtensionValue(ExtensionObject):

hugr-py/src/hugr/ops.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def ext_op(self) -> ExtOp:
230230
Computed once using :meth:`op_def` :meth:`type_args` and :meth:`type_args`.
231231
Each of those methods should be deterministic.
232232
"""
233-
return ExtOp(self.op_def(), self.cached_signature(), self.type_args())
233+
return self.op_def().instantiate(self.type_args(), self.cached_signature())
234234

235235
def op_def(self) -> ext.OpDef:
236236
"""The :class:`tys.OpDef` for this operation.
@@ -657,7 +657,7 @@ def name(self) -> str:
657657
class DataflowBlock(DfParentOp):
658658
"""Parent of non-entry basic block in a control flow graph."""
659659

660-
#: Inputs types of the innner dataflow graph.
660+
#: Inputs types of the inner dataflow graph.
661661
inputs: tys.TypeRow
662662
_sum: tys.Sum | None = None
663663
_other_outputs: tys.TypeRow | None = field(default=None, repr=False)
@@ -879,7 +879,7 @@ def name(self) -> str:
879879
class Case(DfParentOp):
880880
"""Parent of a dataflow graph that is a branch of a :class:`Conditional`."""
881881

882-
#: Inputs types of the innner dataflow graph.
882+
#: Inputs types of the inner dataflow graph.
883883
inputs: tys.TypeRow
884884
_outputs: tys.TypeRow | None = field(default=None, repr=False)
885885
num_out: int = field(default=0, repr=False)

0 commit comments

Comments
 (0)