Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: cleanups from writing docstring #1232

Merged
merged 7 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hugr-py/src/hugr/serialization/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class TupleValue(BaseValue):
vs: list["Value"]

def deserialize(self) -> val.Value:
return val.Tuple(deser_it((v.root for v in self.vs)))
return val.Tuple(*deser_it((v.root for v in self.vs)))


class SumValue(BaseValue):
Expand Down
11 changes: 7 additions & 4 deletions hugr-py/src/hugr/val.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ def bool_value(b: bool) -> Sum:


@dataclass
class Tuple(Value):
class Tuple(Sum):
vals: list[Value]

def type_(self) -> tys.Tuple:
return tys.Tuple(*(v.type_() for v in self.vals))
def __init__(self, *vals: Value):
val_list = list(vals)
super().__init__(
tag=0, typ=tys.Tuple(*(v.type_() for v in val_list)), vals=val_list
)

def to_serial(self) -> sops.TupleValue:
def to_serial(self) -> sops.TupleValue: # type: ignore[override]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why the ignore is needed?
It seems straightforward code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sops.TupleValue isn't an instance of sops.SumValue so mypy doesn't like the override of Sum.to_serial

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will add comment

return sops.TupleValue(
vs=ser_it(self.vals),
)
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 @@ -196,7 +196,7 @@ def test_ancestral_sibling():
[
val.Function(simple_id().hugr),
val.Sum(1, tys.Sum([[INT_T], [tys.Bool, INT_T]]), [val.TRUE, IntVal(34)]),
val.Tuple([val.TRUE, IntVal(23)]),
val.Tuple(val.TRUE, IntVal(23)),
],
)
def test_vals(val: val.Value):
Expand Down