diff --git a/doc/main/micropython/builtins.rst b/doc/main/micropython/builtins.rst index 56a80c5..13267d7 100644 --- a/doc/main/micropython/builtins.rst +++ b/doc/main/micropython/builtins.rst @@ -7,6 +7,8 @@ Classes and types .. autoclass:: ubuiltins.bool +.. autoclass:: ubuiltins.bytearray + .. autoclass:: ubuiltins.bytes .. autoclass:: ubuiltins.complex diff --git a/src/ubuiltins/__init__.py b/src/ubuiltins/__init__.py index 8738686..232ec39 100644 --- a/src/ubuiltins/__init__.py +++ b/src/ubuiltins/__init__.py @@ -42,6 +42,7 @@ import usys # These get overridden later on, but we still want to use the originals # for the purpose of typing the doc strings. _bool = bool +_bytearray = bytearray _bytes = bytes _callable = callable _complex = complex @@ -143,6 +144,33 @@ class bytes: """ +class bytearray: + @overload + def __init__(self) -> None: + ... + + @overload + def __init__(self, source: _int) -> None: + ... + + @overload + def __init__(self, source: Union[_bytes, _bytearray, _str, Iterable[_int]]) -> None: + ... + + def __init__(self, *args): + """ + Creates a new ``bytearray`` object, which is a sequence of integers + in the range ``0 <= x <= 255``. This object is mutable, which means + that you can change its contents after you create it. + + * If no argument is given, this creates an empty ``bytearray``. + * If the ``source`` argument is an integer, this creates a ``bytearray`` + of zeros. The argument specifies how many zeros. + * For all other valid ``source`` arguments, this creates a bytearray with + the same byte sequence as the given ``source`` argument. + """ + + def callable(object: Any) -> _bool: """ Returns ``True`` if the object argument appears callable, ``False`` if not.