From 646ae98d3995b902a53110f7f96eb2b2c95b06e1 Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Mon, 4 Mar 2024 14:23:42 +0000 Subject: [PATCH] `ruff format` --- guppylang/hugr/visualise.py | 1 + guppylang/prelude/builtins.py | 552 ++++++++---------------- guppylang/prelude/quantum.py | 63 +-- tests/integration/test_basic.py | 3 +- tests/integration/test_comprehension.py | 36 +- tests/integration/test_linear.py | 24 +- tests/integration/test_poly.py | 69 +-- tests/integration/test_unused.py | 2 +- 8 files changed, 251 insertions(+), 499 deletions(-) diff --git a/guppylang/hugr/visualise.py b/guppylang/hugr/visualise.py index 08375a4f..bf47e540 100644 --- a/guppylang/hugr/visualise.py +++ b/guppylang/hugr/visualise.py @@ -1,4 +1,5 @@ """Visualise HUGR using graphviz.""" + import ast from collections.abc import Iterable from typing import TYPE_CHECKING diff --git a/guppylang/prelude/builtins.py b/guppylang/prelude/builtins.py index 37fdc270..194e0000 100644 --- a/guppylang/prelude/builtins.py +++ b/guppylang/prelude/builtins.py @@ -35,433 +35,331 @@ @guppy.extend_type(builtins, BoolType) class Bool: @guppy.hugr_op(builtins, logic_op("And", [tys.BoundedNatArg(n=2)])) - def __and__(self: bool, other: bool) -> bool: - ... + def __and__(self: bool, other: bool) -> bool: ... @guppy.custom(builtins, NoopCompiler()) - def __bool__(self: bool) -> bool: - ... + def __bool__(self: bool) -> bool: ... @guppy.hugr_op(builtins, int_op("ifrombool")) - def __int__(self: bool) -> int: - ... + def __int__(self: bool) -> int: ... @guppy.hugr_op(builtins, logic_op("Or", [tys.BoundedNatArg(n=2)])) - def __or__(self: bool, other: bool) -> bool: - ... + def __or__(self: bool, other: bool) -> bool: ... @guppy.type(builtins, hugr_int_type, name="int") class Int: @guppy.hugr_op(builtins, int_op("iabs")) # TODO: Maybe wrong? (signed vs unsigned!) - def __abs__(self: int) -> int: - ... + def __abs__(self: int) -> int: ... @guppy.hugr_op(builtins, int_op("iadd")) - def __add__(self: int, other: int) -> int: - ... + def __add__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("iand")) - def __and__(self: int, other: int) -> int: - ... + def __and__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("itobool")) - def __bool__(self: int) -> bool: - ... + def __bool__(self: int) -> bool: ... @guppy.custom(builtins, NoopCompiler()) - def __ceil__(self: int) -> int: - ... + def __ceil__(self: int) -> int: ... @guppy.hugr_op(builtins, int_op("idivmod_s", num_params=2)) - def __divmod__(self: int, other: int) -> tuple[int, int]: - ... + def __divmod__(self: int, other: int) -> tuple[int, int]: ... @guppy.hugr_op(builtins, int_op("ieq")) - def __eq__(self: int, other: int) -> bool: - ... + def __eq__(self: int, other: int) -> bool: ... @guppy.hugr_op(builtins, int_op("convert_s", "arithmetic.conversions")) - def __float__(self: int) -> float: - ... + def __float__(self: int) -> float: ... @guppy.custom(builtins, NoopCompiler()) - def __floor__(self: int) -> int: - ... + def __floor__(self: int) -> int: ... @guppy.hugr_op(builtins, int_op("idiv_s", num_params=2)) - def __floordiv__(self: int, other: int) -> int: - ... + def __floordiv__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("ige_s")) - def __ge__(self: int, other: int) -> bool: - ... + def __ge__(self: int, other: int) -> bool: ... @guppy.hugr_op(builtins, int_op("igt_s")) - def __gt__(self: int, other: int) -> bool: - ... + def __gt__(self: int, other: int) -> bool: ... @guppy.custom(builtins, NoopCompiler()) - def __int__(self: int) -> int: - ... + def __int__(self: int) -> int: ... @guppy.hugr_op(builtins, int_op("inot")) - def __invert__(self: int) -> bool: - ... + def __invert__(self: int) -> bool: ... @guppy.hugr_op(builtins, int_op("ile_s")) - def __le__(self: int, other: int) -> bool: - ... + def __le__(self: int, other: int) -> bool: ... @guppy.hugr_op(builtins, int_op("ishl", num_params=2)) # TODO: RHS is unsigned - def __lshift__(self: int, other: int) -> int: - ... + def __lshift__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("ilt_s")) - def __lt__(self: int, other: int) -> bool: - ... + def __lt__(self: int, other: int) -> bool: ... @guppy.hugr_op(builtins, int_op("imod_s", num_params=2)) - def __mod__(self: int, other: int) -> int: - ... + def __mod__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("imul")) - def __mul__(self: int, other: int) -> int: - ... + def __mul__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("ine")) - def __ne__(self: int, other: int) -> bool: - ... + def __ne__(self: int, other: int) -> bool: ... @guppy.hugr_op(builtins, int_op("ineg")) - def __neg__(self: int) -> int: - ... + def __neg__(self: int) -> int: ... @guppy.hugr_op(builtins, int_op("ior")) - def __or__(self: int, other: int) -> int: - ... + def __or__(self: int, other: int) -> int: ... @guppy.custom(builtins, NoopCompiler()) - def __pos__(self: int) -> int: - ... + def __pos__(self: int) -> int: ... @guppy.hugr_op(builtins, ops.DummyOp(name="ipow")) # TODO - def __pow__(self: int, other: int) -> int: - ... + def __pow__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("iadd"), ReversingChecker()) - def __radd__(self: int, other: int) -> int: - ... + def __radd__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("rand"), ReversingChecker()) - def __rand__(self: int, other: int) -> int: - ... + def __rand__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("idivmod_s", num_params=2), ReversingChecker()) - def __rdivmod__(self: int, other: int) -> tuple[int, int]: - ... + def __rdivmod__(self: int, other: int) -> tuple[int, int]: ... @guppy.hugr_op(builtins, int_op("idiv_s", num_params=2), ReversingChecker()) - def __rfloordiv__(self: int, other: int) -> int: - ... + def __rfloordiv__(self: int, other: int) -> int: ... @guppy.hugr_op( builtins, int_op("ishl", num_params=2), ReversingChecker() ) # TODO: RHS is unsigned - def __rlshift__(self: int, other: int) -> int: - ... + def __rlshift__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("imod_s", num_params=2), ReversingChecker()) - def __rmod__(self: int, other: int) -> int: - ... + def __rmod__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("imul"), ReversingChecker()) - def __rmul__(self: int, other: int) -> int: - ... + def __rmul__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("ior"), ReversingChecker()) - def __ror__(self: int, other: int) -> int: - ... + def __ror__(self: int, other: int) -> int: ... @guppy.custom(builtins, NoopCompiler()) - def __round__(self: int) -> int: - ... + def __round__(self: int) -> int: ... @guppy.hugr_op(builtins, ops.DummyOp(name="ipow"), ReversingChecker()) # TODO - def __rpow__(self: int, other: int) -> int: - ... + def __rpow__(self: int, other: int) -> int: ... @guppy.hugr_op( builtins, int_op("ishr", num_params=2), ReversingChecker() ) # TODO: RHS is unsigned - def __rrshift__(self: int, other: int) -> int: - ... + def __rrshift__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("ishr", num_params=2)) # TODO: RHS is unsigned - def __rshift__(self: int, other: int) -> int: - ... + def __rshift__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("isub"), ReversingChecker()) - def __rsub__(self: int, other: int) -> int: - ... + def __rsub__(self: int, other: int) -> int: ... @guppy.custom(builtins, IntTruedivCompiler(), ReversingChecker()) - def __rtruediv__(self: int, other: int) -> float: - ... + def __rtruediv__(self: int, other: int) -> float: ... @guppy.hugr_op(builtins, int_op("ixor"), ReversingChecker()) - def __rxor__(self: int, other: int) -> int: - ... + def __rxor__(self: int, other: int) -> int: ... @guppy.hugr_op(builtins, int_op("isub")) - def __sub__(self: int, other: int) -> int: - ... + def __sub__(self: int, other: int) -> int: ... @guppy.custom(builtins, IntTruedivCompiler()) - def __truediv__(self: int, other: int) -> float: - ... + def __truediv__(self: int, other: int) -> float: ... @guppy.custom(builtins, NoopCompiler()) - def __trunc__(self: int) -> int: - ... + def __trunc__(self: int) -> int: ... @guppy.hugr_op(builtins, int_op("ixor")) - def __xor__(self: int, other: int) -> int: - ... + def __xor__(self: int, other: int) -> int: ... @guppy.type(builtins, hugr_float_type, name="float", bound=tys.TypeBound.Copyable) class Float: @guppy.hugr_op(builtins, float_op("fabs"), CoercingChecker()) - def __abs__(self: float) -> float: - ... + def __abs__(self: float) -> float: ... @guppy.hugr_op(builtins, float_op("fadd"), CoercingChecker()) - def __add__(self: float, other: float) -> float: - ... + def __add__(self: float, other: float) -> float: ... @guppy.custom(builtins, FloatBoolCompiler(), CoercingChecker()) - def __bool__(self: float) -> bool: - ... + def __bool__(self: float) -> bool: ... @guppy.hugr_op(builtins, float_op("fceil"), CoercingChecker()) - def __ceil__(self: float) -> float: - ... + def __ceil__(self: float) -> float: ... @guppy.custom(builtins, FloatDivmodCompiler(), CoercingChecker()) - def __divmod__(self: float, other: float) -> tuple[float, float]: - ... + def __divmod__(self: float, other: float) -> tuple[float, float]: ... @guppy.hugr_op(builtins, float_op("feq"), CoercingChecker()) - def __eq__(self: float, other: float) -> bool: - ... + def __eq__(self: float, other: float) -> bool: ... @guppy.custom(builtins, NoopCompiler(), CoercingChecker()) - def __float__(self: float) -> float: - ... + def __float__(self: float) -> float: ... @guppy.hugr_op(builtins, float_op("ffloor"), CoercingChecker()) - def __floor__(self: float) -> float: - ... + def __floor__(self: float) -> float: ... @guppy.custom(builtins, FloatFloordivCompiler(), CoercingChecker()) - def __floordiv__(self: float, other: float) -> float: - ... + def __floordiv__(self: float, other: float) -> float: ... @guppy.hugr_op(builtins, float_op("fge"), CoercingChecker()) - def __ge__(self: float, other: float) -> bool: - ... + def __ge__(self: float, other: float) -> bool: ... @guppy.hugr_op(builtins, float_op("fgt"), CoercingChecker()) - def __gt__(self: float, other: float) -> bool: - ... + def __gt__(self: float, other: float) -> bool: ... @guppy.hugr_op( builtins, float_op("trunc_s", "arithmetic.conversions"), CoercingChecker() ) - def __int__(self: float) -> int: - ... + def __int__(self: float) -> int: ... @guppy.hugr_op(builtins, float_op("fle"), CoercingChecker()) - def __le__(self: float, other: float) -> bool: - ... + def __le__(self: float, other: float) -> bool: ... @guppy.hugr_op(builtins, float_op("flt"), CoercingChecker()) - def __lt__(self: float, other: float) -> bool: - ... + def __lt__(self: float, other: float) -> bool: ... @guppy.custom(builtins, FloatModCompiler(), CoercingChecker()) - def __mod__(self: float, other: float) -> float: - ... + def __mod__(self: float, other: float) -> float: ... @guppy.hugr_op(builtins, float_op("fmul"), CoercingChecker()) - def __mul__(self: float, other: float) -> float: - ... + def __mul__(self: float, other: float) -> float: ... @guppy.hugr_op(builtins, float_op("fne"), CoercingChecker()) - def __ne__(self: float, other: float) -> bool: - ... + def __ne__(self: float, other: float) -> bool: ... @guppy.hugr_op(builtins, float_op("fneg"), CoercingChecker()) - def __neg__(self: float, other: float) -> float: - ... + def __neg__(self: float, other: float) -> float: ... @guppy.custom(builtins, NoopCompiler(), CoercingChecker()) - def __pos__(self: float) -> float: - ... + def __pos__(self: float) -> float: ... @guppy.hugr_op(builtins, ops.DummyOp(name="fpow")) # TODO - def __pow__(self: float, other: float) -> float: - ... + def __pow__(self: float, other: float) -> float: ... @guppy.hugr_op(builtins, float_op("fadd"), ReversingChecker(CoercingChecker())) - def __radd__(self: float, other: float) -> float: - ... + def __radd__(self: float, other: float) -> float: ... @guppy.custom(builtins, FloatDivmodCompiler(), ReversingChecker(CoercingChecker())) - def __rdivmod__(self: float, other: float) -> tuple[float, float]: - ... + def __rdivmod__(self: float, other: float) -> tuple[float, float]: ... @guppy.custom( builtins, FloatFloordivCompiler(), ReversingChecker(CoercingChecker()) ) - def __rfloordiv__(self: float, other: float) -> float: - ... + def __rfloordiv__(self: float, other: float) -> float: ... @guppy.custom(builtins, FloatModCompiler(), ReversingChecker(CoercingChecker())) - def __rmod__(self: float, other: float) -> float: - ... + def __rmod__(self: float, other: float) -> float: ... @guppy.hugr_op(builtins, float_op("fmul"), ReversingChecker(CoercingChecker())) - def __rmul__(self: float, other: float) -> float: - ... + def __rmul__(self: float, other: float) -> float: ... @guppy.hugr_op(builtins, ops.DummyOp(name="fround")) # TODO - def __round__(self: float) -> float: - ... + def __round__(self: float) -> float: ... @guppy.hugr_op( builtins, ops.DummyOp(name="fpow"), ReversingChecker(DefaultCallChecker()) ) # TODO - def __rpow__(self: float, other: float) -> float: - ... + def __rpow__(self: float, other: float) -> float: ... @guppy.hugr_op(builtins, float_op("fsub"), ReversingChecker(CoercingChecker())) - def __rsub__(self: float, other: float) -> float: - ... + def __rsub__(self: float, other: float) -> float: ... @guppy.hugr_op(builtins, float_op("fdiv"), ReversingChecker(CoercingChecker())) - def __rtruediv__(self: float, other: float) -> float: - ... + def __rtruediv__(self: float, other: float) -> float: ... @guppy.hugr_op(builtins, float_op("fsub"), CoercingChecker()) - def __sub__(self: float, other: float) -> float: - ... + def __sub__(self: float, other: float) -> float: ... @guppy.hugr_op(builtins, float_op("fdiv"), CoercingChecker()) - def __truediv__(self: float, other: float) -> float: - ... + def __truediv__(self: float, other: float) -> float: ... @guppy.hugr_op( builtins, float_op("trunc_s", "arithmetic.conversions"), CoercingChecker() ) - def __trunc__(self: float) -> float: - ... + def __trunc__(self: float) -> float: ... @guppy.extend_type(builtins, ListType) class List: @guppy.hugr_op(builtins, ops.DummyOp(name="Concat")) - def __add__(self: list[T], other: list[T]) -> list[T]: - ... + def __add__(self: list[T], other: list[T]) -> list[T]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="IsEmpty")) - def __bool__(self: list[T]) -> bool: - ... + def __bool__(self: list[T]) -> bool: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Contains")) - def __contains__(self: list[T], el: T) -> bool: - ... + def __contains__(self: list[T], el: T) -> bool: ... @guppy.hugr_op(builtins, ops.DummyOp(name="AssertEmpty")) - def __end__(self: list[T]) -> None: - ... + def __end__(self: list[T]) -> None: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Lookup")) - def __getitem__(self: list[T], idx: int) -> T: - ... + def __getitem__(self: list[T], idx: int) -> T: ... @guppy.hugr_op(builtins, ops.DummyOp(name="IsNonEmpty")) - def __hasnext__(self: list[T]) -> tuple[bool, list[T]]: - ... + def __hasnext__(self: list[T]) -> tuple[bool, list[T]]: ... @guppy.custom(builtins, NoopCompiler()) - def __iter__(self: list[T]) -> list[T]: - ... + def __iter__(self: list[T]) -> list[T]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Length")) - def __len__(self: list[T]) -> int: - ... + def __len__(self: list[T]) -> int: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Repeat")) - def __mul__(self: list[T], other: int) -> list[T]: - ... + def __mul__(self: list[T], other: int) -> list[T]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Pop")) - def __next__(self: list[T]) -> tuple[T, list[T]]: - ... + def __next__(self: list[T]) -> tuple[T, list[T]]: ... @guppy.custom(builtins, checker=FailingChecker("Guppy lists are immutable")) - def __setitem__(self: list[T], idx: int, value: T) -> None: - ... + def __setitem__(self: list[T], idx: int, value: T) -> None: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Append"), ReversingChecker()) - def __radd__(self: list[T], other: list[T]) -> list[T]: - ... + def __radd__(self: list[T], other: list[T]) -> list[T]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Repeat"), ReversingChecker()) - def __rmul__(self: list[T], other: int) -> list[T]: - ... + def __rmul__(self: list[T], other: int) -> list[T]: ... @guppy.custom(builtins, checker=FailingChecker("Guppy lists are immutable")) - def append(self: list[T], elt: T) -> None: - ... + def append(self: list[T], elt: T) -> None: ... @guppy.custom(builtins, checker=FailingChecker("Guppy lists are immutable")) - def clear(self: list[T]) -> None: - ... + def clear(self: list[T]) -> None: ... @guppy.custom(builtins, NoopCompiler()) # Can be noop since lists are immutable - def copy(self: list[T]) -> list[T]: - ... + def copy(self: list[T]) -> list[T]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Count")) - def count(self: list[T], elt: T) -> int: - ... + def count(self: list[T], elt: T) -> int: ... @guppy.custom(builtins, checker=FailingChecker("Guppy lists are immutable")) - def extend(self: list[T], seq: None) -> None: - ... + def extend(self: list[T], seq: None) -> None: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Find")) - def index(self: list[T], elt: T) -> int: - ... + def index(self: list[T], elt: T) -> int: ... @guppy.custom(builtins, checker=FailingChecker("Guppy lists are immutable")) - def pop(self: list[T], idx: int) -> None: - ... + def pop(self: list[T], idx: int) -> None: ... @guppy.custom(builtins, checker=FailingChecker("Guppy lists are immutable")) - def remove(self: list[T], elt: T) -> None: - ... + def remove(self: list[T], elt: T) -> None: ... @guppy.custom(builtins, checker=FailingChecker("Guppy lists are immutable")) - def reverse(self: list[T]) -> None: - ... + def reverse(self: list[T]) -> None: ... @guppy.custom(builtins, checker=FailingChecker("Guppy lists are immutable")) - def sort(self: list[T]) -> None: - ... + def sort(self: list[T]) -> None: ... linst = list @@ -470,416 +368,334 @@ def sort(self: list[T]) -> None: @guppy.extend_type(builtins, LinstType) class Linst: @guppy.hugr_op(builtins, ops.DummyOp(name="Append")) - def __add__(self: linst[L], other: linst[L]) -> linst[L]: - ... + def __add__(self: linst[L], other: linst[L]) -> linst[L]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="AssertEmpty")) - def __end__(self: linst[L]) -> None: - ... + def __end__(self: linst[L]) -> None: ... @guppy.hugr_op(builtins, ops.DummyOp(name="IsNonempty")) - def __hasnext__(self: linst[L]) -> tuple[bool, linst[L]]: - ... + def __hasnext__(self: linst[L]) -> tuple[bool, linst[L]]: ... @guppy.custom(builtins, NoopCompiler()) - def __iter__(self: linst[L]) -> linst[L]: - ... + def __iter__(self: linst[L]) -> linst[L]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Length")) - def __len__(self: linst[L]) -> tuple[int, linst[L]]: - ... + def __len__(self: linst[L]) -> tuple[int, linst[L]]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Pop")) - def __next__(self: linst[L]) -> tuple[L, linst[L]]: - ... + def __next__(self: linst[L]) -> tuple[L, linst[L]]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Append"), ReversingChecker()) - def __radd__(self: linst[L], other: linst[L]) -> linst[L]: - ... + def __radd__(self: linst[L], other: linst[L]) -> linst[L]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Repeat"), ReversingChecker()) - def __rmul__(self: linst[L], other: int) -> linst[L]: - ... + def __rmul__(self: linst[L], other: int) -> linst[L]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Push")) - def append(self: linst[L], elt: L) -> linst[L]: - ... + def append(self: linst[L], elt: L) -> linst[L]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="PopAt")) - def pop(self: linst[L], idx: int) -> tuple[L, linst[L]]: - ... + def pop(self: linst[L], idx: int) -> tuple[L, linst[L]]: ... @guppy.hugr_op(builtins, ops.DummyOp(name="Reverse")) - def reverse(self: linst[L]) -> linst[L]: - ... + def reverse(self: linst[L]) -> linst[L]: ... @guppy.custom(builtins, checker=FailingChecker("Guppy lists are immutable")) - def sort(self: list[T]) -> None: - ... + def sort(self: list[T]) -> None: ... @guppy.custom(builtins, checker=DunderChecker("__abs__"), higher_order_value=False) -def abs(x): - ... +def abs(x): ... @guppy.custom( builtins, name="bool", checker=DunderChecker("__bool__"), higher_order_value=False ) -def _bool(x): - ... +def _bool(x): ... @guppy.custom(builtins, checker=CallableChecker(), higher_order_value=False) -def callable(x): - ... +def callable(x): ... @guppy.custom( builtins, checker=DunderChecker("__divmod__", num_args=2), higher_order_value=False ) -def divmod(x, y): - ... +def divmod(x, y): ... @guppy.custom( builtins, name="float", checker=DunderChecker("__float__"), higher_order_value=False ) -def _float(x, y): - ... +def _float(x, y): ... @guppy.custom( builtins, name="int", checker=DunderChecker("__int__"), higher_order_value=False ) -def _int(x): - ... +def _int(x): ... @guppy.custom(builtins, checker=DunderChecker("__len__"), higher_order_value=False) -def len(x): - ... +def len(x): ... @guppy.custom( builtins, checker=DunderChecker("__pow__", num_args=2), higher_order_value=False ) -def pow(x, y): - ... +def pow(x, y): ... @guppy.custom(builtins, checker=DunderChecker("__round__"), higher_order_value=False) -def round(x): - ... +def round(x): ... # Python builtins that are not supported yet: @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def aiter(x): - ... +def aiter(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def all(x): - ... +def all(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def anext(x): - ... +def anext(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def any(x): - ... +def any(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def bin(x): - ... +def bin(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def breakpoint(x): - ... +def breakpoint(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def bytearray(x): - ... +def bytearray(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def bytes(x): - ... +def bytes(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def chr(x): - ... +def chr(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def classmethod(x): - ... +def classmethod(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def compile(x): - ... +def compile(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def complex(x): - ... +def complex(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def delattr(x): - ... +def delattr(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def dict(x): - ... +def dict(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def dir(x): - ... +def dir(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def enumerate(x): - ... +def enumerate(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def eval(x): - ... +def eval(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def exec(x): - ... +def exec(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def filter(x): - ... +def filter(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def format(x): - ... +def format(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def forozenset(x): - ... +def forozenset(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def getattr(x): - ... +def getattr(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def globals(): - ... +def globals(): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def hasattr(x): - ... +def hasattr(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def hash(x): - ... +def hash(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def help(x): - ... +def help(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def hex(x): - ... +def hex(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def id(x): - ... +def id(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def input(x): - ... +def input(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def isinstance(x): - ... +def isinstance(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def issubclass(x): - ... +def issubclass(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def iter(x): - ... +def iter(x): ... @guppy.custom( builtins, checker=UnsupportedChecker(), name="list", higher_order_value=False ) -def _list(x): - ... +def _list(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def locals(x): - ... +def locals(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def map(x): - ... +def map(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def max(x): - ... +def max(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def memoryview(x): - ... +def memoryview(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def min(x): - ... +def min(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def next(x): - ... +def next(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def object(x): - ... +def object(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def oct(x): - ... +def oct(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def open(x): - ... +def open(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def ord(x): - ... +def ord(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def print(x): - ... +def print(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def property(x): - ... +def property(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def range(x): - ... +def range(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def repr(x): - ... +def repr(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def reversed(x): - ... +def reversed(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def set(x): - ... +def set(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def setattr(x): - ... +def setattr(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def slice(x): - ... +def slice(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def sorted(x): - ... +def sorted(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def staticmethod(x): - ... +def staticmethod(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def str(x): - ... +def str(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def sum(x): - ... +def sum(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def super(x): - ... +def super(x): ... @guppy.custom( builtins, name="tuple", checker=UnsupportedChecker(), higher_order_value=False ) -def _tuple(x): - ... +def _tuple(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def type(x): - ... +def type(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def vars(x): - ... +def vars(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def zip(x): - ... +def zip(x): ... @guppy.custom(builtins, checker=UnsupportedChecker(), higher_order_value=False) -def __import__(x): - ... +def __import__(x): ... diff --git a/guppylang/prelude/quantum.py b/guppylang/prelude/quantum.py index a683e5a9..26602bfd 100644 --- a/guppylang/prelude/quantum.py +++ b/guppylang/prelude/quantum.py @@ -26,105 +26,84 @@ class Qubit: @guppy.hugr_op(quantum, quantum_op("H")) -def h(q: Qubit) -> Qubit: - ... +def h(q: Qubit) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("CZ")) -def cz(control: Qubit, target: Qubit) -> tuple[Qubit, Qubit]: - ... +def cz(control: Qubit, target: Qubit) -> tuple[Qubit, Qubit]: ... @guppy.hugr_op(quantum, quantum_op("CX")) -def cx(control: Qubit, target: Qubit) -> tuple[Qubit, Qubit]: - ... +def cx(control: Qubit, target: Qubit) -> tuple[Qubit, Qubit]: ... @guppy.hugr_op(quantum, quantum_op("T")) -def t(q: Qubit) -> Qubit: - ... +def t(q: Qubit) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("S")) -def s(q: Qubit) -> Qubit: - ... +def s(q: Qubit) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("X")) -def x(q: Qubit) -> Qubit: - ... +def x(q: Qubit) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("Y")) -def y(q: Qubit) -> Qubit: - ... +def y(q: Qubit) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("Z")) -def z(q: Qubit) -> Qubit: - ... +def z(q: Qubit) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("Tdg")) -def tdg(q: Qubit) -> Qubit: - ... +def tdg(q: Qubit) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("Sdg")) -def sdg(q: Qubit) -> Qubit: - ... +def sdg(q: Qubit) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("ZZMax")) -def zz_max(q: Qubit) -> Qubit: - ... +def zz_max(q: Qubit) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("Measure")) -def measure_return(q: Qubit) -> tuple[Qubit, bool]: - ... +def measure_return(q: Qubit) -> tuple[Qubit, bool]: ... @guppy.hugr_op(quantum, quantum_op("RzF64")) -def rz(q: Qubit, angle: float) -> Qubit: - ... +def rz(q: Qubit, angle: float) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("RxF64")) -def rx(q: Qubit, angle: float) -> Qubit: - ... +def rx(q: Qubit, angle: float) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("RzF64")) -def phased_x(q: Qubit, angle1: float, angle2: float) -> Qubit: - ... +def phased_x(q: Qubit, angle1: float, angle2: float) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("RzF64")) -def zz_phase(q1: Qubit, q2: Qubit, angle: float) -> tuple[Qubit, Qubit]: - ... +def zz_phase(q1: Qubit, q2: Qubit, angle: float) -> tuple[Qubit, Qubit]: ... @guppy.hugr_op(quantum, quantum_op("RzF64")) -def tk1(q: Qubit, angle1: float, angle2: float, angle3: float) -> Qubit: - ... +def tk1(q: Qubit, angle1: float, angle2: float, angle3: float) -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("QAlloc"), name="Qubit") -def _Qubit() -> Qubit: - ... +def _Qubit() -> Qubit: ... @guppy.hugr_op(quantum, quantum_op("QFree")) -def discard(q: Qubit) -> None: - ... +def discard(q: Qubit) -> None: ... @guppy.hugr_op(quantum, quantum_op("Reset")) -def reset(q: Qubit) -> Qubit: - ... +def reset(q: Qubit) -> Qubit: ... @guppy.custom(quantum, MeasureCompiler()) -def measure(q: Qubit) -> bool: - ... +def measure(q: Qubit) -> bool: ... diff --git a/tests/integration/test_basic.py b/tests/integration/test_basic.py index bb57695e..c2f9c3c2 100644 --- a/tests/integration/test_basic.py +++ b/tests/integration/test_basic.py @@ -75,8 +75,7 @@ def test_func_decl_name(): module = GuppyModule("test") @guppy.declare(module) - def func_name() -> None: - ... + def func_name() -> None: ... [def_op] = [ n.op for n in module.compile().nodes() if isinstance(n.op, ops.FuncDecl) diff --git a/tests/integration/test_comprehension.py b/tests/integration/test_comprehension.py index 76da7749..9e71ad76 100644 --- a/tests/integration/test_comprehension.py +++ b/tests/integration/test_comprehension.py @@ -74,8 +74,7 @@ def test_dependent(validate): module = GuppyModule("test") @guppy.declare(module) - def process(x: float) -> list[int]: - ... + def process(x: float) -> list[int]: ... @guppy(module) def test(xs: list[float]) -> list[float]: @@ -145,8 +144,7 @@ def test_linear_discard(validate): module.load(quantum) @guppy.declare(module) - def discard(q: Qubit) -> None: - ... + def discard(q: Qubit) -> None: ... @guppy(module) def test(qs: linst[Qubit]) -> list[None]: @@ -160,8 +158,7 @@ def test_linear_consume_in_guard(validate): module.load(quantum) @guppy.declare(module) - def cond(q: Qubit) -> bool: - ... + def cond(q: Qubit) -> bool: ... @guppy(module) def test(qs: linst[tuple[int, Qubit]]) -> list[int]: @@ -175,8 +172,7 @@ def test_linear_consume_in_iter(validate): module.load(quantum) @guppy.declare(module) - def make_list(q: Qubit) -> list[int]: - ... + def make_list(q: Qubit) -> list[int]: ... @guppy(module) def test(qs: linst[Qubit]) -> list[int]: @@ -194,24 +190,20 @@ class MyIter: """An iterator that yields linear values but is not linear itself.""" @guppy.declare(module) - def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]: - ... + def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]: ... @guppy.declare(module) - def __next__(self: "MyIter") -> tuple[Qubit, "MyIter"]: - ... + def __next__(self: "MyIter") -> tuple[Qubit, "MyIter"]: ... @guppy.declare(module) - def __end__(self: "MyIter") -> None: - ... + def __end__(self: "MyIter") -> None: ... @guppy.type(module, tys.TupleType(inner=[])) class MyType: """Type that produces the iterator above.""" @guppy.declare(module) - def __iter__(self: "MyType") -> MyIter: - ... + def __iter__(self: "MyType") -> MyIter: ... @guppy(module) def test(mt: MyType, xs: list[int]) -> linst[tuple[int, Qubit]]: @@ -234,24 +226,20 @@ class MyIter: """A linear iterator that yields non-linear values.""" @guppy.declare(module) - def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]: - ... + def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]: ... @guppy.declare(module) - def __next__(self: "MyIter") -> tuple[int, "MyIter"]: - ... + def __next__(self: "MyIter") -> tuple[int, "MyIter"]: ... @guppy.declare(module) - def __end__(self: "MyIter") -> None: - ... + def __end__(self: "MyIter") -> None: ... @guppy.type(module, tys.TupleType(inner=[])) class MyType: """Type that produces the iterator above.""" @guppy.declare(module) - def __iter__(self: "MyType") -> MyIter: - ... + def __iter__(self: "MyType") -> MyIter: ... @guppy(module) def test(mt: MyType, xs: list[int]) -> linst[tuple[int, int]]: diff --git a/tests/integration/test_linear.py b/tests/integration/test_linear.py index 197257b7..31defea6 100644 --- a/tests/integration/test_linear.py +++ b/tests/integration/test_linear.py @@ -49,12 +49,10 @@ def test_interleave(validate): module.load(quantum) @guppy.declare(module) - def f(q1: Qubit, q2: Qubit) -> tuple[Qubit, Qubit]: - ... + def f(q1: Qubit, q2: Qubit) -> tuple[Qubit, Qubit]: ... @guppy.declare(module) - def g(q1: Qubit, q2: Qubit) -> tuple[Qubit, Qubit]: - ... + def g(q1: Qubit, q2: Qubit) -> tuple[Qubit, Qubit]: ... @guppy(module) def test( @@ -117,8 +115,7 @@ def test_return_call(validate): module.load(quantum) @guppy.declare(module) - def op(q: Qubit) -> Qubit: - ... + def op(q: Qubit) -> Qubit: ... @guppy(module) def test(q: Qubit) -> Qubit: @@ -243,28 +240,23 @@ class MyIter: """An iterator that yields linear values but is not linear itself.""" @guppy.declare(module) - def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]: - ... + def __hasnext__(self: "MyIter") -> tuple[bool, "MyIter"]: ... @guppy.declare(module) - def __next__(self: "MyIter") -> tuple[Qubit, "MyIter"]: - ... + def __next__(self: "MyIter") -> tuple[Qubit, "MyIter"]: ... @guppy.declare(module) - def __end__(self: "MyIter") -> None: - ... + def __end__(self: "MyIter") -> None: ... @guppy.type(module, tys.TupleType(inner=[])) class MyType: """Type that produces the iterator above.""" @guppy.declare(module) - def __iter__(self: "MyType") -> MyIter: - ... + def __iter__(self: "MyType") -> MyIter: ... @guppy.declare(module) - def measure(q: Qubit) -> bool: - ... + def measure(q: Qubit) -> bool: ... @guppy(module) def test(mt: MyType, xs: list[int]) -> None: diff --git a/tests/integration/test_poly.py b/tests/integration/test_poly.py index f05e708e..7e986e3c 100644 --- a/tests/integration/test_poly.py +++ b/tests/integration/test_poly.py @@ -12,8 +12,7 @@ def test_id(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo(x: T) -> T: - ... + def foo(x: T) -> T: ... @guppy(module) def main(x: int) -> int: @@ -27,8 +26,7 @@ def test_id_nested(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo(x: T) -> T: - ... + def foo(x: T) -> T: ... @guppy(module) def main(x: int) -> int: @@ -42,8 +40,7 @@ def test_use_twice(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo(x: T) -> T: - ... + def foo(x: T) -> T: ... @guppy(module) def main(x: int, y: bool) -> None: @@ -58,8 +55,7 @@ def test_define_twice(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo(x: T) -> T: - ... + def foo(x: T) -> T: ... @guppy.declare(module) def bar(x: T) -> T: # Reuse same type var! @@ -78,8 +74,7 @@ def test_return_tuple_implicit(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo(x: T) -> T: - ... + def foo(x: T) -> T: ... @guppy(module) def main(x: int) -> tuple[int, int]: @@ -93,8 +88,7 @@ def test_same_args(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo(x: T, y: T) -> None: - ... + def foo(x: T, y: T) -> None: ... @guppy(module) def main(x: int) -> None: @@ -109,8 +103,7 @@ def test_different_args(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo(x: S, y: T, z: tuple[S, T]) -> T: - ... + def foo(x: S, y: T, z: tuple[S, T]) -> T: ... @guppy(module) def main(x: int, y: float) -> float: @@ -124,8 +117,7 @@ def test_infer_basic(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo() -> T: - ... + def foo() -> T: ... @guppy(module) def main() -> None: @@ -139,8 +131,7 @@ def test_infer_list(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo() -> T: - ... + def foo() -> T: ... @guppy(module) def main() -> None: @@ -155,12 +146,10 @@ def test_infer_nested(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo() -> T: - ... + def foo() -> T: ... @guppy.declare(module) - def bar(x: T) -> T: - ... + def bar(x: T) -> T: ... @guppy(module) def main() -> None: @@ -175,12 +164,10 @@ def test_infer_left_to_right(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo() -> T: - ... + def foo() -> T: ... @guppy.declare(module) - def bar(x: T, y: T, z: S, a: tuple[T, S]) -> None: - ... + def bar(x: T, y: T, z: S, a: tuple[T, S]) -> None: ... @guppy(module) def main() -> None: @@ -194,12 +181,10 @@ def test_pass_poly_basic(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo(f: Callable[[T], T]) -> None: - ... + def foo(f: Callable[[T], T]) -> None: ... @guppy.declare(module) - def bar(x: int) -> int: - ... + def bar(x: int) -> int: ... @guppy(module) def main() -> None: @@ -214,12 +199,10 @@ def test_pass_poly_cross(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo(f: Callable[[S], int]) -> None: - ... + def foo(f: Callable[[S], int]) -> None: ... @guppy.declare(module) - def bar(x: bool) -> T: - ... + def bar(x: bool) -> T: ... @guppy(module) def main() -> None: @@ -234,8 +217,7 @@ def test_linear(validate): T = guppy.type_var(module, "T", linear=True) @guppy.declare(module) - def foo(x: T) -> T: - ... + def foo(x: T) -> T: ... @guppy(module) def main(q: Qubit) -> Qubit: @@ -250,8 +232,7 @@ def test_pass_nonlinear(validate): T = guppy.type_var(module, "T", linear=True) @guppy.declare(module) - def foo(x: T) -> T: - ... + def foo(x: T) -> T: ... @guppy(module) def main(x: int) -> None: @@ -266,12 +247,10 @@ def test_pass_linear(validate): T = guppy.type_var(module, "T", linear=True) @guppy.declare(module) - def foo(f: Callable[[T], T]) -> None: - ... + def foo(f: Callable[[T], T]) -> None: ... @guppy.declare(module) - def bar(q: Qubit) -> Qubit: - ... + def bar(q: Qubit) -> Qubit: ... @guppy(module) def main() -> None: @@ -285,12 +264,10 @@ def test_higher_order_value(validate): T = guppy.type_var(module, "T") @guppy.declare(module) - def foo(x: T) -> T: - ... + def foo(x: T) -> T: ... @guppy.declare(module) - def bar(x: T) -> T: - ... + def bar(x: T) -> T: ... @guppy(module) def main(b: bool) -> int: diff --git a/tests/integration/test_unused.py b/tests/integration/test_unused.py index f4b5b01f..7ce8a79d 100644 --- a/tests/integration/test_unused.py +++ b/tests/integration/test_unused.py @@ -1,4 +1,4 @@ -""" All sorts of weird stuff is allowed when variables are not used. """ +"""All sorts of weird stuff is allowed when variables are not used.""" from tests.util import compile_guppy