Skip to content

Commit

Permalink
ubuiltins: Document bytes, bytearray, type.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurensvalk committed Nov 28, 2022
1 parent 7dd3eda commit cbf6eb9
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions src/ubuiltins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,27 @@ def __init__(self, source: _str, encoding: _str) -> None:

def __init__(self, *args):
r"""
bytes(​)
bytes(integer)
bytes(iterable)
bytes(string, "utf-8")
Creates a new ``bytes`` object, which is a sequence of integers
in the range :math:`0 \leq x \leq 255`. This object is *immutable*,
which means that you *cannot* change its contents after you create it.
* If no argument is given, this creates an empty ``bytes`` object.
* If the ``source`` argument is an integer, this creates a ``bytes``
object of zeros. The argument specifies how many zeros.
* If ``source`` is a ``bytearray``, ``bytes`` object, or some other
iterable of integers, this creates a ``bytes``
object with the same byte sequence as the ``source`` argument.
* If ``source`` is a string, choose ``'utf8'`` as the ``encoding``
argument. Then this creates a ``bytes`` object containing the
encoded string.
If no argument is given, this creates an empty ``bytes`` object.
Arguments:
integer (int): If the argument is a single integer, this creates
a ``bytes`` object of zeros. The argument specifies how many.
iterable (iter): If the argument is a ``bytearray``, ``bytes``
object, or some other iterable of integers, this creates a ``bytes``
object with the same byte sequence as the argument.
string (str): If the argument is a string, this creates a ``bytes``
object containing the encoded string.
encoding (str): Specifies which encoding to use for the ``string``
argument. Only ``'utf8'`` is supported.
"""


Expand All @@ -208,15 +216,25 @@ def __init__(self, source: Union[_bytes, _bytearray, _str, Iterable[_int]]) -> N

def __init__(self, *args):
r"""
bytearray(​)
bytearray(integer)
bytearray(iterable)
bytearray(string)
Creates a new ``bytearray`` object, which is a sequence of integers
in the range :math:`0 \leq x \leq 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.
If no argument is given, this creates an empty ``bytearray`` object.
Arguments:
integer (int): If the argument is a single integer, this creates
a ``bytearray`` object of zeros. The argument specifies how many.
iterable (iter): If the argument is a ``bytearray``, ``bytes``
object, or some other iterable of integers, this creates
a ``bytearray`` object with the same byte sequence as the argument.
string (str): If the argument is a string, this creates
a ``bytearray`` object containing the encoded string.
"""


Expand Down Expand Up @@ -306,6 +324,8 @@ def __init__(self, *args, **kwargs) -> None:
dict(mapping, **kwargs)
dict(iterable, **kwargs)
Creates a dictionary object.
See the standard
`Python documentation
<https://docs.python.org/3/library/stdtypes.html#mapping-types-dict>`_
Expand Down Expand Up @@ -709,7 +729,7 @@ def next(*args):
class object:
def __init__(self) -> None:
"""
Return a new featureless object.
Creates a new, featureless object.
"""


Expand Down Expand Up @@ -967,7 +987,7 @@ def super(type: _type, object_or_type: Any) -> _type:

def super(*args):
"""
Returns am object that delegates method calls to a parent or sibling class
Returns an object that delegates method calls to a parent or sibling class
of ``type``.
"""

Expand All @@ -990,8 +1010,13 @@ def __init__(self, *args) -> None:

class type:
def __init__(self, object: Any) -> None:
"""
With one argument, returns the type of an ``object``.
"""type(object)
Gets the type of an object. This can be used to check if an object
is an instance of a particular class.
Arguments:
object: Object of which to check the type.
"""


Expand Down

0 comments on commit cbf6eb9

Please sign in to comment.