From d7096dad80db900a042489a418de23a4624b9ba1 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Fri, 6 Aug 2021 14:24:50 +0200 Subject: [PATCH] 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 --- src/ubuiltins/__init__.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ubuiltins/__init__.py b/src/ubuiltins/__init__.py index e7fb184..c2ec941 100644 --- a/src/ubuiltins/__init__.py +++ b/src/ubuiltins/__init__.py @@ -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``. """