Skip to content
Open
Changes from 2 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
19 changes: 19 additions & 0 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ _NegativeInteger: TypeAlias = Literal[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -
_LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed

class int:
@overload
def __new__(cls) -> Literal[0]: ...
@overload
def __new__(cls, __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ...
@overload
Expand Down Expand Up @@ -432,6 +434,8 @@ class _TranslateTable(Protocol):
def __getitem__(self, __key: int) -> str | int | None: ...

class str(Sequence[str]):
@overload
def __new__(cls) -> Literal[""]: ...
@overload
def __new__(cls, object: object = ...) -> Self: ...
@overload
Expand Down Expand Up @@ -612,6 +616,8 @@ class str(Sequence[str]):
def __getnewargs__(self) -> tuple[str]: ...

class bytes(Sequence[int]):
@overload
def __new__(cls) -> Literal[b""]: ...
@overload
def __new__(cls, __o: Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer) -> Self: ...
@overload
Expand Down Expand Up @@ -898,8 +904,21 @@ class memoryview(Sequence[int]):
def __buffer__(self, __flags: int) -> memoryview: ...
def __release_buffer__(self, __buffer: memoryview) -> None: ...

class _Truthy(Protocol):
def __bool__(self) -> Literal[True]: ...

class _Falsy(Protocol):
def __bool__(self) -> Literal[False]: ...

@final
class bool(int):
@overload
def __new__(cls) -> Literal[False]: ...
@overload
def __new__(cls, __o: _Truthy) -> Literal[True]: ...
@overload
def __new__(cls, __o: _Falsy) -> Literal[False]: ...
@overload
def __new__(cls, __o: object = ...) -> Self: ...
# The following overloads could be represented more elegantly with a TypeVar("_B", bool, int),
# however mypy has a bug regarding TypeVar constraints (https://github.com/python/mypy/issues/11880).
Expand Down