Skip to content

Revert "add overload to tuple.__new__ to better express an empty tuple" #8278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,7 @@ class slice:
def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ...

class tuple(Sequence[_T_co], Generic[_T_co]):
# overloads are ordered this way to pass `isinstance` checks
# see: https://github.com/python/typeshed/pull/7454#issuecomment-1061490888
@overload
def __new__(cls: type[Self], __iterable: Iterable[_T_co]) -> Self: ...
@overload
def __new__(cls) -> tuple[()]: ...
def __new__(cls: type[Self], __iterable: Iterable[_T_co] = ...) -> Self: ...
def __len__(self) -> int: ...
def __contains__(self, __x: object) -> bool: ...
@overload
Expand Down
11 changes: 11 additions & 0 deletions test_cases/stdlib/builtins/test_tuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing_extensions import assert_type
from typing import Tuple


# Empty tuples, see #8275
class TupleSub(Tuple[int, ...]):
pass


assert_type(TupleSub(), TupleSub)
assert_type(TupleSub([1, 2, 3]), TupleSub)