diff --git a/guppylang/std/_internal/compiler/option.py b/guppylang/std/_internal/compiler/option.py index 3a2b5840..3ec5c118 100644 --- a/guppylang/std/_internal/compiler/option.py +++ b/guppylang/std/_internal/compiler/option.py @@ -24,7 +24,7 @@ def option_ty(self) -> ht.Option: class OptionConstructor(OptionCompiler, CustomCallCompiler): - """Compiler for the `Option` constructors `none` and `some`.""" + """Compiler for the `Option` constructors `nothing` and `some`.""" def __init__(self, tag: int): self.tag = tag @@ -34,7 +34,7 @@ def compile(self, args: list[Wire]) -> list[Wire]: class OptionTestCompiler(OptionCompiler): - """Compiler for the `Option.is_none` and `Option.is_none` methods.""" + """Compiler for the `Option.is_nothing` and `Option.is_some` methods.""" def __init__(self, tag: int): self.tag = tag @@ -56,6 +56,5 @@ class OptionUnwrapCompiler(OptionCompiler, CustomCallCompiler): def compile(self, args: list[Wire]) -> list[Wire]: [opt] = args - return list( - build_unwrap(self.builder, opt, "Option.unwrap: value is `None`").outputs() - ) + err = "Option.unwrap: value is `Nothing`" + return list(build_unwrap(self.builder, opt, err).outputs()) diff --git a/guppylang/std/option.py b/guppylang/std/option.py index dd4f43e7..9359e168 100644 --- a/guppylang/std/option.py +++ b/guppylang/std/option.py @@ -32,8 +32,8 @@ class Option(Generic[T]): # type: ignore[misc] @guppy.custom(OptionTestCompiler(0)) @no_type_check - def is_none(self: "Option[T]") -> bool: - """Returns `True` if the option is a `none` value.""" + def is_nothing(self: "Option[T]") -> bool: + """Returns `True` if the option is a `nothing` value.""" @guppy.custom(OptionTestCompiler(1)) @no_type_check @@ -45,14 +45,14 @@ def is_some(self: "Option[T]") -> bool: def unwrap(self: "Option[T]" @ owned) -> T: """Returns the contained `some` value, consuming `self`. - Panics if the option is a `none` value. + Panics if the option is a `nothing` value. """ @guppy.custom(OptionConstructor(0)) @no_type_check -def none() -> Option[T]: - """Constructs a `none` optional value.""" +def nothing() -> Option[T]: + """Constructs a `nothing` optional value.""" @guppy.custom(OptionConstructor(1)) diff --git a/tests/integration/test_option.py b/tests/integration/test_option.py index 1281163b..db491643 100644 --- a/tests/integration/test_option.py +++ b/tests/integration/test_option.py @@ -1,16 +1,16 @@ from guppylang.decorator import guppy from guppylang.module import GuppyModule -from guppylang.std.option import Option, none, some +from guppylang.std.option import Option, nothing, some def test_none(validate, run_int_fn): module = GuppyModule("test_range") - module.load(Option, none) + module.load(Option, nothing) @guppy(module) def main() -> int: - x: Option[int] = none() - is_none = 10 if x.is_none() else 0 + x: Option[int] = nothing() + is_none = 10 if x.is_nothing() else 0 is_some = 1 if x.is_some() else 0 return is_none + is_some @@ -26,7 +26,7 @@ def test_some_unwrap(validate, run_int_fn): @guppy(module) def main() -> int: x: Option[int] = some(42) - is_none = 1 if x.is_none() else 0 + is_none = 1 if x.is_nothing() else 0 is_some = x.unwrap() if x.is_some() else 0 return is_none + is_some