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

[stdlib] Make NoneType Boolable #4150

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 0 additions & 9 deletions mojo/stdlib/src/builtin/bool.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,6 @@ struct Bool(
"""
self = value.__bool__()

@always_inline
fn __init__(out self, value: None):
"""Set the bool representation of the `None` type to `False`.

Args:
value: The object to get the bool representation of.
"""
self = False

@always_inline("nodebug")
@implicit
fn __init__(out self, value: SIMD[DType.bool, 1]):
Expand Down
10 changes: 10 additions & 0 deletions mojo/stdlib/src/builtin/none.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ These are Mojo built-ins, so you don't need to import them.
@value
@register_passable("trivial")
struct NoneType(
Boolable,
CollectionElement,
CollectionElementNew,
Writable,
Expand Down Expand Up @@ -56,6 +57,15 @@ struct NoneType(
"""
return Self(None)

@always_inline("nodebug")
fn __bool__(self) -> Bool:
"""Returns `False` for `None`.

Returns:
`False`.
"""
return False

@no_inline
fn __str__(self) -> String:
"""Returns the string representation of `None`.
Expand Down
Loading