ubuiltins.complex: Document it.

Override typed docstrings in order to hide types like SupportsFloat and SupportsComplex.

Avoid use of ``real`` and ``imag``, since both ``a`` and ``b`` can be
either.

Also reduce number of overloads by letting ``b`` default to 0, which is true in practice.

See also https://github.com/pybricks/pybricks-api/issues/84
This commit is contained in:
Laurens Valk
2021-08-06 14:25:00 +02:00
parent 1d2b1f0307
commit d7096dad80
+17 -3
View File
@@ -231,9 +231,23 @@ class complex:
...
def __init__(self, *args) -> None:
"""
Returns a complex number with the value `real + imag*1j` or converts a
string or number to a complex number.
"""complex()
complex(string: str)
complex(a: Union[float, complex], b: Union[float, complex] = 0)
Creates a complex number from a string or from a pair of numbers.
If a string is given, it must be of the form ``'1+2j'``.
If a pair of numbers is provided, the result is computed
as: ``a + b * j``.
Arguments:
string: A string of the form ``'1+2j'`` .
a: A real-valued or complex number.
b: A real-valued or complex number.
Returns:
Complex number, obtained from the string or as the result of ``a + b * j``.
"""