Skip to content

Commit

Permalink
refactor: replace Sequence[Type] with TypeRow
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Jun 17, 2024
1 parent 8611316 commit b7e9dc5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
8 changes: 2 additions & 6 deletions hugr-py/src/hugr/_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down
16 changes: 6 additions & 10 deletions hugr-py/src/hugr/_dfg.py
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 12 in hugr-py/src/hugr/_dfg.py

View check run for this annotation

Codecov / codecov/patch

hugr-py/src/hugr/_dfg.py#L12

Added line #L12 was not covered by tests
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)


Expand Down
5 changes: 2 additions & 3 deletions hugr-py/src/hugr/_hugr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b7e9dc5

Please sign in to comment.