Skip to content

Commit

Permalink
make constructor for Some simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Dec 18, 2024
1 parent 59dbaf6 commit 1e9eee2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions hugr-py/src/hugr/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,16 @@ def __repr__(self) -> str:

@dataclass
class Some(Tag):
"""Tag operation for the `Some` variant of an Option type."""
"""Tag operation for the `Some` variant of an Option type.
def __init__(self, option_type: tys.Option) -> None:
super().__init__(1, option_type)
Example:
# construct a Some variant holding a row of Bool and Unit types
>>> Some(tys.Bool, tys.Unit)
Some
"""

def __init__(self, *some_tys: tys.Type) -> None:
super().__init__(1, tys.Option(*some_tys))

def __repr__(self) -> str:
return "Some"
Expand Down
2 changes: 1 addition & 1 deletion hugr-py/tests/test_hugr_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def test_option() -> None:
dfg = Dfg(tys.Bool)
b = dfg.inputs()[0]

dfg.add_op(ops.Some(tys.Option(tys.Bool)), b)
dfg.add_op(ops.Some(tys.Bool), b)

dfg.set_outputs(b)

Expand Down

0 comments on commit 1e9eee2

Please sign in to comment.