Skip to content

Commit bc74659

Browse files
authored
python#8440: Update parameter types in complex.__new__
For two-parameter overload: - Change first parameter to complex | SupportsComplex | SupportsFloat - Change second parameter to complex | SupportsFloat (Python doesn't allow SupportsComplex for the second parameter, though it isn't clear why) - Add SupportsIndex to both parameters for Python >= 3.8 For one-parameter overload: - Remove SupportsIndex for Python < 3.8
1 parent f550c24 commit bc74659

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

stdlib/builtins.pyi

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,17 @@ class float:
364364
def __bool__(self) -> bool: ...
365365

366366
class complex:
367-
@overload
368-
def __new__(cls: type[Self], real: float = ..., imag: float = ...) -> Self: ...
369-
@overload
370-
def __new__(cls: type[Self], real: str | SupportsComplex | SupportsIndex | complex) -> Self: ...
367+
if sys.version_info >= (3, 8):
368+
# Python doesn't currently accept SupportsComplex for the second argument
369+
@overload
370+
def __new__(cls: type[Self], real: complex | SupportsComplex | SupportsFloat | SupportsIndex = ..., imag: complex | SupportsFloat | SupportsIndex = ...) -> Self: ...
371+
@overload
372+
def __new__(cls: type[Self], real: str | SupportsComplex | SupportsIndex | complex) -> Self: ...
373+
else:
374+
@overload
375+
def __new__(cls: type[Self], real: complex | SupportsComplex | SupportsFloat = ..., imag: complex | SupportsFloat = ...) -> Self: ...
376+
@overload
377+
def __new__(cls: type[Self], real: str | SupportsComplex | complex) -> Self: ...
371378
@property
372379
def real(self) -> float: ...
373380
@property

0 commit comments

Comments
 (0)