Skip to content

Commit

Permalink
Sync typeshed
Browse files Browse the repository at this point in the history
  • Loading branch information
mypybot committed Dec 15, 2024
1 parent ce14043 commit 7e0b499
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 16 deletions.
6 changes: 5 additions & 1 deletion mypy/typeshed/stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType):
def _type_(self) -> type[_CT]: ...
@_type_.setter
def _type_(self, value: type[_CT]) -> None: ...
raw: bytes # Note: only available if _CT == c_char
# Note: only available if _CT == c_char
@property
def raw(self) -> bytes: ...
@raw.setter
def raw(self, value: ReadableBuffer) -> None: ...
value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise
# TODO These methods cannot be annotated correctly at the moment.
# All of these "Any"s stand for the array's element type, but it's not possible to use _CT
Expand Down
5 changes: 3 additions & 2 deletions mypy/typeshed/stdlib/_sitebuiltins.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import sys
from collections.abc import Iterable
from typing import ClassVar, Literal, NoReturn

class Quitter:
name: str
eof: str
def __init__(self, name: str, eof: str) -> None: ...
def __call__(self, code: int | None = None) -> NoReturn: ...
def __call__(self, code: sys._ExitCode = None) -> NoReturn: ...

class _Printer:
MAXLINES: ClassVar[Literal[23]]
def __init__(self, name: str, data: str, files: Iterable[str] = (), dirs: Iterable[str] = ()) -> None: ...
def __call__(self) -> None: ...

class _Helper:
def __call__(self, request: object) -> None: ...
def __call__(self, request: object = ...) -> None: ...
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/asyncio/proactor_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ class _ProactorSocketTransport(_ProactorReadPipeTransport, _ProactorBaseWritePip

class BaseProactorEventLoop(base_events.BaseEventLoop):
def __init__(self, proactor: Any) -> None: ...
async def sock_recv(self, sock: socket, n: int) -> bytes: ...
2 changes: 2 additions & 0 deletions mypy/typeshed/stdlib/asyncio/selector_events.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import selectors
from socket import socket

from . import base_events

__all__ = ("BaseSelectorEventLoop",)

class BaseSelectorEventLoop(base_events.BaseEventLoop):
def __init__(self, selector: selectors.BaseSelector | None = None) -> None: ...
async def sock_recv(self, sock: socket, n: int) -> bytes: ...
123 changes: 114 additions & 9 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ruff: noqa: PYI036 # This is the module declaring BaseException
import _ast
import _sitebuiltins
import _typeshed
import sys
import types
Expand Down Expand Up @@ -46,7 +47,6 @@ from typing import ( # noqa: Y022
Mapping,
MutableMapping,
MutableSequence,
NoReturn,
Protocol,
Sequence,
SupportsAbs,
Expand All @@ -64,6 +64,7 @@ from typing import ( # noqa: Y022
from typing_extensions import ( # noqa: Y023
Concatenate,
Literal,
LiteralString,
ParamSpec,
Self,
TypeAlias,
Expand Down Expand Up @@ -441,16 +442,31 @@ class str(Sequence[str]):
def __new__(cls, object: object = ...) -> Self: ...
@overload
def __new__(cls, object: ReadableBuffer, encoding: str = ..., errors: str = ...) -> Self: ...
@overload
def capitalize(self: LiteralString) -> LiteralString: ...
@overload
def capitalize(self) -> str: ... # type: ignore[misc]
@overload
def casefold(self: LiteralString) -> LiteralString: ...
@overload
def casefold(self) -> str: ... # type: ignore[misc]
@overload
def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
@overload
def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
def count(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
def encode(self, encoding: str = "utf-8", errors: str = "strict") -> bytes: ...
def endswith(
self, suffix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
) -> bool: ...
@overload
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
@overload
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
def find(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
@overload
def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ...
@overload
def format(self, *args: object, **kwargs: object) -> str: ...
def format_map(self, mapping: _FormatMapMapping, /) -> str: ...
def index(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
Expand All @@ -466,35 +482,99 @@ class str(Sequence[str]):
def isspace(self) -> bool: ...
def istitle(self) -> bool: ...
def isupper(self) -> bool: ...
@overload
def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ...
@overload
def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc]
@overload
def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
@overload
def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
@overload
def lower(self: LiteralString) -> LiteralString: ...
@overload
def lower(self) -> str: ... # type: ignore[misc]
@overload
def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
@overload
def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
@overload
def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
@overload
def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
if sys.version_info >= (3, 13):
@overload
def replace(
self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1
) -> LiteralString: ...
@overload
def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc]
else:
@overload
def replace(
self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, /
) -> LiteralString: ...
@overload
def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc]
if sys.version_info >= (3, 9):
@overload
def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ...
@overload
def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc]
@overload
def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ...
@overload
def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc]

def rfind(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
def rindex(self, sub: str, start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /) -> int: ...
@overload
def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ...
@overload
def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc]
@overload
def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ...
@overload
def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc]
@overload
def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
@overload
def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
@overload
def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
@overload
def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
@overload
def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ...
@overload
def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc]
@overload
def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ...
@overload
def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc]
def startswith(
self, prefix: str | tuple[str, ...], start: SupportsIndex | None = ..., end: SupportsIndex | None = ..., /
) -> bool: ...
@overload
def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ...
@overload
def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc]
@overload
def swapcase(self: LiteralString) -> LiteralString: ...
@overload
def swapcase(self) -> str: ... # type: ignore[misc]
@overload
def title(self: LiteralString) -> LiteralString: ...
@overload
def title(self) -> str: ... # type: ignore[misc]
def translate(self, table: _TranslateTable, /) -> str: ...
@overload
def upper(self: LiteralString) -> LiteralString: ...
@overload
def upper(self) -> str: ... # type: ignore[misc]
@overload
def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ...
@overload
def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc]
@staticmethod
@overload
Expand All @@ -505,21 +585,39 @@ class str(Sequence[str]):
@staticmethod
@overload
def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ...
@overload
def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ...
@overload
def __add__(self, value: str, /) -> str: ... # type: ignore[misc]
# Incompatible with Sequence.__contains__
def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
def __eq__(self, value: object, /) -> bool: ...
def __ge__(self, value: str, /) -> bool: ...
def __getitem__(self, key: SupportsIndex | slice, /) -> str: ...
@overload
def __getitem__(self: LiteralString, key: SupportsIndex | slice, /) -> LiteralString: ...
@overload
def __getitem__(self, key: SupportsIndex | slice, /) -> str: ... # type: ignore[misc]
def __gt__(self, value: str, /) -> bool: ...
def __hash__(self) -> int: ...
@overload
def __iter__(self: LiteralString) -> Iterator[LiteralString]: ...
@overload
def __iter__(self) -> Iterator[str]: ... # type: ignore[misc]
def __le__(self, value: str, /) -> bool: ...
def __len__(self) -> int: ...
def __lt__(self, value: str, /) -> bool: ...
@overload
def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ...
@overload
def __mod__(self, value: Any, /) -> str: ...
@overload
def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
@overload
def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
def __ne__(self, value: object, /) -> bool: ...
@overload
def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
@overload
def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]
def __getnewargs__(self) -> tuple[str]: ...

Expand Down Expand Up @@ -1264,8 +1362,10 @@ def compile(
*,
_feature_version: int = -1,
) -> Any: ...
def copyright() -> None: ...
def credits() -> None: ...

copyright: _sitebuiltins._Printer
credits: _sitebuiltins._Printer

def delattr(obj: object, name: str, /) -> None: ...
def dir(o: object = ..., /) -> list[str]: ...
@overload
Expand Down Expand Up @@ -1320,7 +1420,7 @@ else:
/,
) -> None: ...

def exit(code: sys._ExitCode = None) -> NoReturn: ...
exit: _sitebuiltins.Quitter

class filter(Generic[_T]):
@overload
Expand Down Expand Up @@ -1354,7 +1454,9 @@ def getattr(o: object, name: str, default: _T, /) -> Any | _T: ...
def globals() -> dict[str, Any]: ...
def hasattr(obj: object, name: str, /) -> bool: ...
def hash(obj: object, /) -> int: ...
def help(request: object = ...) -> None: ...

help: _sitebuiltins._Helper

def hex(number: int | SupportsIndex, /) -> str: ...
def id(obj: object, /) -> int: ...
def input(prompt: object = "", /) -> str: ...
Expand All @@ -1380,7 +1482,9 @@ else:
def isinstance(obj: object, class_or_tuple: _ClassInfo, /) -> bool: ...
def issubclass(cls: type, class_or_tuple: _ClassInfo, /) -> bool: ...
def len(obj: Sized, /) -> int: ...
def license() -> None: ...

license: _sitebuiltins._Printer

def locals() -> dict[str, Any]: ...

class map(Generic[_S]):
Expand Down Expand Up @@ -1623,7 +1727,8 @@ def pow(base: _SupportsPow3[_E, _M, _T_co], exp: _E, mod: _M) -> _T_co: ...
def pow(base: _SupportsSomeKindOfPow, exp: float, mod: None = None) -> Any: ...
@overload
def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex: ...
def quit(code: sys._ExitCode = None) -> NoReturn: ...

quit: _sitebuiltins.Quitter

class reversed(Generic[_T]):
@overload
Expand Down Expand Up @@ -1673,7 +1778,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
# without creating many false-positive errors (see #7578).
# Instead, we special-case the most common examples of this: bool and literal integers.
@overload
def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ...
def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ...
@overload
def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ...
@overload
Expand Down
7 changes: 5 additions & 2 deletions mypy/typeshed/stdlib/ctypes/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ArgumentError(Exception): ...

class CDLL:
_func_flags_: ClassVar[int]
_func_restype_: ClassVar[_CDataType]
_func_restype_: ClassVar[type[_CDataType]]
_name: str
_handle: int
_FuncPtr: type[_FuncPointer]
Expand Down Expand Up @@ -202,7 +202,10 @@ if sys.platform == "win32":
class HRESULT(_SimpleCData[int]): ... # TODO undocumented

if sys.version_info >= (3, 12):
c_time_t: type[c_int32 | c_int64] # alias for one or the other at runtime
# At runtime, this is an alias for either c_int32 or c_int64,
# which are themselves an alias for one of c_short, c_int, c_long, or c_longlong
# This covers all our bases.
c_time_t: type[c_int32 | c_int64 | c_short | c_int | c_long | c_longlong]

class py_object(_CanCastTo, _SimpleCData[_T]): ...

Expand Down
4 changes: 2 additions & 2 deletions mypy/typeshed/stdlib/fractions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class Fraction(Rational):
@overload
def __new__(cls, numerator: int | Rational = 0, denominator: int | Rational | None = None) -> Self: ...
@overload
def __new__(cls, value: float | Decimal | str, /) -> Self: ...
def __new__(cls, numerator: float | Decimal | str) -> Self: ...

if sys.version_info >= (3, 14):
@overload
def __new__(cls, value: _ConvertibleToIntegerRatio) -> Self: ...
def __new__(cls, numerator: _ConvertibleToIntegerRatio) -> Self: ...

@classmethod
def from_float(cls, f: float) -> Self: ...
Expand Down
2 changes: 2 additions & 0 deletions mypy/typeshed/stdlib/optparse.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ class Values:
def ensure_value(self, attr: str, value): ...
def read_file(self, filename: str, mode: str = "careful") -> None: ...
def read_module(self, modname: str, mode: str = "careful") -> None: ...
# __getattr__ doesn't exist, but anything passed as a default to __init__
# is set on the instance.
def __getattr__(self, name: str): ...
def __setattr__(self, name: str, value, /) -> None: ...
def __eq__(self, other: object) -> bool: ...
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ if sys.platform == "linux" and sys.version_info >= (3, 12):
"CLONE_NEWNET",
"CLONE_NEWNS",
"CLONE_NEWPID",
"CLONE_NEWTIME",
"CLONE_NEWUSER",
"CLONE_NEWUTS",
"CLONE_SIGHAND",
Expand Down
2 changes: 2 additions & 0 deletions mypy/typeshed/stdlib/traceback.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ if sys.version_info >= (3, 11):
class TracebackException:
__cause__: TracebackException
__context__: TracebackException
if sys.version_info >= (3, 11):
exceptions: list[TracebackException] | None
__suppress_context__: bool
stack: StackSummary
filename: str
Expand Down

0 comments on commit 7e0b499

Please sign in to comment.