mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-11 17:14:41 +00:00
ubuiltins: Document int.
This commit is contained in:
@@ -36,26 +36,12 @@ Basic types
|
||||
|
||||
.. pybricks-requirements::
|
||||
|
||||
..
|
||||
_comment: The int class is defined manually because otherwise the classmethod is hidden, see https://github.com/pybricks/pybricks-api/issues/86
|
||||
|
||||
.. autoclass:: ubuiltins.int
|
||||
:no-members:
|
||||
|
||||
.. automethod:: ubuiltins.int.to_bytes
|
||||
|
||||
.. classmethod:: from_bytes(bytes: Union[bytes, bytearray], byteorder: Literal["little", "big"]) -> int
|
||||
|
||||
Returns the integer represented by the given bytes.
|
||||
|
||||
:param bytes: The bytes to convert.
|
||||
:param byteorder: Determines the byte order used to represent the
|
||||
integer. If byteorder is ``"big"``, the most significant byte is at
|
||||
the beginning of the byte sequence. If byteorder is ``"little"``,
|
||||
the most significant byte is at the end of the byte sequence.
|
||||
|
||||
:returns: The integer represented by the bytes.
|
||||
|
||||
.. automethod:: ubuiltins.int.from_bytes
|
||||
|
||||
.. pybricks-requirements::
|
||||
|
||||
|
||||
+25
-20
@@ -436,13 +436,10 @@ class float:
|
||||
def __init__(self, *args) -> None:
|
||||
"""float(x=0.0)
|
||||
|
||||
Converts an object to a floating point number.
|
||||
Creates a floating point number from a given object.
|
||||
|
||||
Arguments:
|
||||
x (int or float or str): Number or string to be converted.
|
||||
|
||||
Returns:
|
||||
The resulting floating point value.
|
||||
"""
|
||||
|
||||
|
||||
@@ -564,36 +561,44 @@ class int:
|
||||
...
|
||||
|
||||
def __init__(self, *args) -> None:
|
||||
"""int()
|
||||
int(x: Union[int, float, str])
|
||||
"""int(x=0)
|
||||
|
||||
Converts the argument to an integer. If no argument is given, this
|
||||
returns ``0``.
|
||||
Creates an integer.
|
||||
|
||||
Arguments:
|
||||
x: Number or string that will be converted.
|
||||
|
||||
Returns:
|
||||
The input argument ``x`` converted to an integer.
|
||||
x (int or float or str): Object to be converted.
|
||||
"""
|
||||
|
||||
def to_bytes(self, length: _int, byteorder: Literal["little", "big"]) -> _bytes:
|
||||
"""
|
||||
Returns a :class:`bytes` object representing the integer.
|
||||
to_bytes(length, byteorder) -> bytes
|
||||
|
||||
Get a :class:`bytes` representation of the integer.
|
||||
|
||||
Arguments:
|
||||
length: How many bytes to use.
|
||||
byteorder: Choose ``"little"`` for little-endian encoding
|
||||
or ``"big"`` for big-endian encoding.
|
||||
length (int): How many bytes to use.
|
||||
byteorder (str): Choose ``"big"`` to put the most significant byte
|
||||
first. Choose ``"little"`` to put the least significant byte
|
||||
first.
|
||||
|
||||
Returns:
|
||||
The integer represented by a sequence of bytes.
|
||||
Byte sequence that represents the integer.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
# @classmethod
|
||||
def from_bytes(cls, _bytes: _bytes, byteorder: Literal["little", "big"]) -> _int:
|
||||
"""
|
||||
Returns the integer represented by the given array of bytes.
|
||||
"""from_bytes(bytes, byteorder) -> int
|
||||
|
||||
Convert a byte sequence to the number it represents.
|
||||
|
||||
Arguments:
|
||||
bytes (bytes): The bytes to convert.
|
||||
byteorder (str): Choose ``"big"`` if the most significant byte is
|
||||
the first element. Choose ``"little"`` if the least significant
|
||||
byte is the first element.
|
||||
|
||||
Returns:
|
||||
The number represented by the bytes.
|
||||
"""
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user