From 93ebd58055f5a5232c22b0f622a489841c91d5da Mon Sep 17 00:00:00 2001 From: Scott Lerman <30610765+smlerman@users.noreply.github.com> Date: Tue, 2 Aug 2022 17:41:18 -0400 Subject: [PATCH] Fix `complex` constructor (#8473) --- stdlib/builtins.pyi | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 1a88e708a..23958919d 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -364,10 +364,24 @@ class float: def __bool__(self) -> bool: ... class complex: - @overload - def __new__(cls: type[Self], real: float = ..., imag: float = ...) -> Self: ... - @overload - def __new__(cls: type[Self], real: str | SupportsComplex | SupportsIndex | complex) -> Self: ... + if sys.version_info >= (3, 8): + # Python doesn't currently accept SupportsComplex for the second argument + @overload + def __new__( + cls: type[Self], + real: complex | SupportsComplex | SupportsFloat | SupportsIndex = ..., + imag: complex | SupportsFloat | SupportsIndex = ..., + ) -> Self: ... + @overload + def __new__(cls: type[Self], real: str | SupportsComplex | SupportsFloat | SupportsIndex | complex) -> Self: ... + else: + @overload + def __new__( + cls: type[Self], real: complex | SupportsComplex | SupportsFloat = ..., imag: complex | SupportsFloat = ... + ) -> Self: ... + @overload + def __new__(cls: type[Self], real: str | SupportsComplex | SupportsFloat | complex) -> Self: ... + @property def real(self) -> float: ... @property