From ec08baed6ed8cc5ad9ce5789aa86e16761264aa5 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 11 Dec 2024 14:05:02 -0300 Subject: [PATCH 1/3] Fix as_bytes() documentation Signed-off-by: martinvuyk --- stdlib/src/builtin/string_literal.mojo | 14 +++++++------- stdlib/src/collections/string.mojo | 8 +++----- stdlib/src/memory/span.mojo | 8 +++----- stdlib/src/utils/string_slice.mojo | 7 +++++-- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/stdlib/src/builtin/string_literal.mojo b/stdlib/src/builtin/string_literal.mojo index 377173470f..b03e0d5a27 100644 --- a/stdlib/src/builtin/string_literal.mojo +++ b/stdlib/src/builtin/string_literal.mojo @@ -526,28 +526,28 @@ struct StringLiteral( @always_inline fn as_bytes(self) -> Span[Byte, StaticConstantOrigin]: - """ - Returns a contiguous Span of the bytes owned by this string. + """Returns a contiguous slice of bytes. Returns: - A contiguous slice pointing to the bytes owned by this string. - """ + A contiguous slice pointing to bytes. + Notes: + This does not include the trailing null terminator. + """ return Span[Byte, StaticConstantOrigin]( ptr=self.unsafe_ptr(), length=self.byte_length() ) @always_inline fn as_bytes(ref self) -> Span[Byte, __origin_of(self)]: - """Returns a contiguous slice of the bytes owned by this string. + """Returns a contiguous slice of bytes. Returns: - A contiguous slice pointing to the bytes owned by this string. + A contiguous slice pointing to bytes. Notes: This does not include the trailing null terminator. """ - # Does NOT include the NUL terminator. return Span[Byte, __origin_of(self)]( ptr=self.unsafe_ptr(), length=self.byte_length() ) diff --git a/stdlib/src/collections/string.mojo b/stdlib/src/collections/string.mojo index fe9746584d..05fbf63045 100644 --- a/stdlib/src/collections/string.mojo +++ b/stdlib/src/collections/string.mojo @@ -1614,18 +1614,16 @@ struct String( @always_inline fn as_bytes(ref self) -> Span[Byte, __origin_of(self)]: - """Returns a contiguous slice of the bytes owned by this string. + """Returns a contiguous slice of bytes. Returns: - A contiguous slice pointing to the bytes owned by this string. + A contiguous slice pointing to bytes. Notes: This does not include the trailing null terminator. """ - - # Does NOT include the NUL terminator. return Span[Byte, __origin_of(self)]( - ptr=self._buffer.unsafe_ptr(), length=self.byte_length() + ptr=self.unsafe_ptr(), length=self.byte_length() ) @always_inline diff --git a/stdlib/src/memory/span.mojo b/stdlib/src/memory/span.mojo index 497a084c88..f807818cf8 100644 --- a/stdlib/src/memory/span.mojo +++ b/stdlib/src/memory/span.mojo @@ -26,16 +26,14 @@ from memory import Pointer, UnsafePointer trait AsBytes: - """ - The `AsBytes` trait denotes a type that can be returned as a immutable byte - span. + """The `AsBytes` trait denotes a type that can be returned as a byte span. """ fn as_bytes(ref self) -> Span[Byte, __origin_of(self)]: - """Returns a contiguous slice of the bytes owned by this string. + """Returns a contiguous slice of bytes. Returns: - A contiguous slice pointing to the bytes owned by this string. + A contiguous slice pointing to bytes. Notes: This does not include the trailing null terminator. diff --git a/stdlib/src/utils/string_slice.mojo b/stdlib/src/utils/string_slice.mojo index 03ed9be490..3557e82aa2 100644 --- a/stdlib/src/utils/string_slice.mojo +++ b/stdlib/src/utils/string_slice.mojo @@ -750,10 +750,13 @@ struct StringSlice[is_mutable: Bool, //, origin: Origin[is_mutable]]( @always_inline fn as_bytes(self) -> Span[Byte, origin]: - """Get the sequence of encoded bytes of the underlying string. + """Returns a contiguous slice of bytes. Returns: - A slice containing the underlying sequence of encoded bytes. + A contiguous slice pointing to bytes. + + Notes: + This does not include the trailing null terminator. """ return self._slice From f5b9cc3df4f172db80247f1f8ff78ffc9ab8bd6c Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 11 Dec 2024 14:08:30 -0300 Subject: [PATCH 2/3] mojo format Signed-off-by: martinvuyk --- stdlib/test/python/my_module.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/test/python/my_module.py b/stdlib/test/python/my_module.py index 8147b0a382..c78c39556e 100644 --- a/stdlib/test/python/my_module.py +++ b/stdlib/test/python/my_module.py @@ -25,7 +25,8 @@ def __init__(self, bar): class AbstractPerson(ABC): @abstractmethod - def method(self): ... + def method(self): + ... def my_function(name): From 989e63afc56a809f218ba67e571ade3aaa1ccff0 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Wed, 11 Dec 2024 14:15:50 -0300 Subject: [PATCH 3/3] unformat my_module.py Signed-off-by: martinvuyk --- stdlib/test/python/my_module.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/test/python/my_module.py b/stdlib/test/python/my_module.py index c78c39556e..8147b0a382 100644 --- a/stdlib/test/python/my_module.py +++ b/stdlib/test/python/my_module.py @@ -25,8 +25,7 @@ def __init__(self, bar): class AbstractPerson(ABC): @abstractmethod - def method(self): - ... + def method(self): ... def my_function(name):