From b7e9dc5f3dd02f17e8bc38b554b92a6e59d0204e Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Mon, 17 Jun 2024 11:15:06 +0100 Subject: [PATCH] refactor: replace `Sequence[Type]` with `TypeRow` --- hugr-py/src/hugr/_cfg.py | 8 ++------ hugr-py/src/hugr/_dfg.py | 16 ++++++---------- hugr-py/src/hugr/_hugr.py | 5 ++--- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/hugr-py/src/hugr/_cfg.py b/hugr-py/src/hugr/_cfg.py index 9a2452c4a..23e1e0808 100644 --- a/hugr-py/src/hugr/_cfg.py +++ b/hugr-py/src/hugr/_cfg.py @@ -3,7 +3,7 @@ from typing import Sequence from ._hugr import Hugr, Node, Wire from ._dfg import DfBase, _from_base -from ._tys import Type, FunctionType, TypeRow, Sum +from ._tys import FunctionType, TypeRow, Sum import hugr._ops as ops @@ -23,11 +23,7 @@ class Cfg: _entry_block: Block exit: Node - def __init__( - self, input_types: Sequence[Type], output_types: Sequence[Type] - ) -> None: - input_types = list(input_types) - output_types = list(output_types) + def __init__(self, input_types: TypeRow, output_types: TypeRow) -> None: root_op = ops.CFG(FunctionType(input=input_types, output=output_types)) self.hugr = Hugr(root_op) self.root = self.hugr.root diff --git a/hugr-py/src/hugr/_dfg.py b/hugr-py/src/hugr/_dfg.py index 54c5c6b58..5f10b5029 100644 --- a/hugr-py/src/hugr/_dfg.py +++ b/hugr-py/src/hugr/_dfg.py @@ -1,12 +1,12 @@ from __future__ import annotations from dataclasses import dataclass -from typing import Sequence, Iterable, TYPE_CHECKING, Generic, TypeVar, cast +from typing import Iterable, TYPE_CHECKING, Generic, TypeVar, cast import typing from ._hugr import Hugr, Node, Wire, OutPort import hugr._ops as ops from ._exceptions import NoSiblingAncestor -from hugr._tys import FunctionType, Type, TypeRow +from hugr._tys import FunctionType, TypeRow if TYPE_CHECKING: from ._cfg import Cfg @@ -75,8 +75,8 @@ def add_nested( def add_cfg( self, - input_types: Sequence[Type], - output_types: Sequence[Type], + input_types: TypeRow, + output_types: TypeRow, *args: Wire, ) -> Cfg: cfg = self.hugr.add_cfg(input_types, output_types) @@ -119,16 +119,12 @@ def _from_base(cls: typing.Type[C], base: DfBase[DP]) -> C: class Dfg(DfBase[ops.DFG]): - def __init__( - self, input_types: Sequence[Type], output_types: Sequence[Type] - ) -> None: - input_types = list(input_types) - output_types = list(output_types) + def __init__(self, input_types: TypeRow, output_types: TypeRow) -> None: root_op = ops.DFG(FunctionType(input=input_types, output=output_types)) super().__init__(root_op) @classmethod - def endo(cls, types: Sequence[Type]) -> Dfg: + def endo(cls, types: TypeRow) -> Dfg: return cls(types, types) diff --git a/hugr-py/src/hugr/_hugr.py b/hugr-py/src/hugr/_hugr.py index a35b87f4a..3bee26bd6 100644 --- a/hugr-py/src/hugr/_hugr.py +++ b/hugr-py/src/hugr/_hugr.py @@ -13,13 +13,12 @@ TypeVar, cast, overload, - Sequence, ) from typing_extensions import Self from hugr._ops import Op -from hugr._tys import Type +from hugr._tys import TypeRow from hugr.serialization.ops import OpType as SerialOp from hugr.serialization.serial_hugr import SerialHugr from hugr.utils import BiMap @@ -349,7 +348,7 @@ def add_dfg(self, root_op: DP) -> DfBase[DP]: dfg.root = mapping[dfg.root] return dfg - def add_cfg(self, input_types: Sequence[Type], output_types: Sequence[Type]) -> Cfg: + def add_cfg(self, input_types: TypeRow, output_types: TypeRow) -> Cfg: from ._cfg import Cfg cfg = Cfg(input_types, output_types)