Skip to content

Commit 64554bd

Browse files
xavdidAlexWaygood
andauthored
add overload to tuple.__new__ to better express an empty tuple (#7454)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 043d9da commit 64554bd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

stdlib/builtins.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,12 @@ class slice:
910910
def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ...
911911

912912
class tuple(Sequence[_T_co], Generic[_T_co]):
913-
def __new__(cls: type[Self], __iterable: Iterable[_T_co] = ...) -> Self: ...
913+
# overloads are ordered this way to pass `isinstance` checks
914+
# see: https://github.com/python/typeshed/pull/7454#issuecomment-1061490888
915+
@overload
916+
def __new__(cls: type[Self], __iterable: Iterable[_T_co]) -> Self: ...
917+
@overload
918+
def __new__(cls) -> tuple[()]: ...
914919
def __len__(self) -> int: ...
915920
def __contains__(self, __x: object) -> bool: ...
916921
@overload

0 commit comments

Comments
 (0)