Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a7439e

Browse files
Revert "add overload to tuple.__new__ to better express an empty tuple" (#8278)
This reverts commit 64554bd. Also add a test case.
1 parent 2a1b33d commit 2a7439e

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

stdlib/builtins.pyi

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -904,12 +904,7 @@ class slice:
904904
def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ...
905905

906906
class tuple(Sequence[_T_co], Generic[_T_co]):
907-
# overloads are ordered this way to pass `isinstance` checks
908-
# see: https://github.com/python/typeshed/pull/7454#issuecomment-1061490888
909-
@overload
910-
def __new__(cls: type[Self], __iterable: Iterable[_T_co]) -> Self: ...
911-
@overload
912-
def __new__(cls) -> tuple[()]: ...
907+
def __new__(cls: type[Self], __iterable: Iterable[_T_co] = ...) -> Self: ...
913908
def __len__(self) -> int: ...
914909
def __contains__(self, __x: object) -> bool: ...
915910
@overload
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing_extensions import assert_type
2+
from typing import Tuple
3+
4+
5+
# Empty tuples, see #8275
6+
class TupleSub(Tuple[int, ...]):
7+
pass
8+
9+
10+
assert_type(TupleSub(), TupleSub)
11+
assert_type(TupleSub([1, 2, 3]), TupleSub)

0 commit comments

Comments
 (0)