Skip to content

Commit

Permalink
Rename none to nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-koch committed Dec 10, 2024
1 parent c803b35 commit a9fdefb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
9 changes: 4 additions & 5 deletions guppylang/std/_internal/compiler/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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())
10 changes: 5 additions & 5 deletions guppylang/std/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_option.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down

0 comments on commit a9fdefb

Please sign in to comment.