Skip to content

Commit

Permalink
Sync typeshed (#16206)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 1, 2023
1 parent acccdd8 commit 7a62481
Show file tree
Hide file tree
Showing 32 changed files with 404 additions and 217 deletions.
6 changes: 6 additions & 0 deletions mypy/typeshed/stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ class _CData(metaclass=_CDataMeta):
_b_base_: int
_b_needsfree_: bool
_objects: Mapping[Any, int] | None
# At runtime the following classmethods are available only on classes, not
# on instances. This can't be reflected properly in the type system:
#
# Structure.from_buffer(...) # valid at runtime
# Structure(...).from_buffer(...) # invalid at runtime
#
@classmethod
def from_buffer(cls, source: WriteableBuffer, offset: int = ...) -> Self: ...
@classmethod
Expand Down
23 changes: 12 additions & 11 deletions mypy/typeshed/stdlib/_curses.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,7 @@ if sys.platform != "win32":
def can_change_color() -> bool: ...
def cbreak(__flag: bool = True) -> None: ...
def color_content(__color_number: int) -> tuple[int, int, int]: ...
# Changed in Python 3.8.8 and 3.9.2
if sys.version_info >= (3, 8):
def color_pair(pair_number: int) -> int: ...
else:
def color_pair(__color_number: int) -> int: ...

def color_pair(__pair_number: int) -> int: ...
def curs_set(__visibility: int) -> int: ...
def def_prog_mode() -> None: ...
def def_shell_mode() -> None: ...
Expand Down Expand Up @@ -366,7 +361,10 @@ if sys.platform != "win32":
) -> bytes: ...
def typeahead(__fd: int) -> None: ...
def unctrl(__ch: _ChType) -> bytes: ...
def unget_wch(__ch: int | str) -> None: ...
if sys.version_info < (3, 12) or sys.platform != "darwin":
# The support for macos was dropped in 3.12
def unget_wch(__ch: int | str) -> None: ...

def ungetch(__ch: _ChType) -> None: ...
def ungetmouse(__id: int, __x: int, __y: int, __z: int, __bstate: int) -> None: ...
def update_lines_cols() -> None: ...
Expand Down Expand Up @@ -441,10 +439,13 @@ if sys.platform != "win32":
def getch(self) -> int: ...
@overload
def getch(self, y: int, x: int) -> int: ...
@overload
def get_wch(self) -> int | str: ...
@overload
def get_wch(self, y: int, x: int) -> int | str: ...
if sys.version_info < (3, 12) or sys.platform != "darwin":
# The support for macos was dropped in 3.12
@overload
def get_wch(self) -> int | str: ...
@overload
def get_wch(self, y: int, x: int) -> int | str: ...

@overload
def getkey(self) -> str: ...
@overload
Expand Down
16 changes: 8 additions & 8 deletions mypy/typeshed/stdlib/_posixsubprocess.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ from typing_extensions import SupportsIndex
if sys.platform != "win32":
def cloexec_pipe() -> tuple[int, int]: ...
def fork_exec(
__process_args: Sequence[StrOrBytesPath] | None,
__args: Sequence[StrOrBytesPath] | None,
__executable_list: Sequence[bytes],
__close_fds: bool,
__fds_to_keep: tuple[int, ...],
__cwd_obj: str,
__env_list: Sequence[bytes] | None,
__pass_fds: tuple[int, ...],
__cwd: str,
__env: Sequence[bytes] | None,
__p2cread: int,
__p2cwrite: int,
__c2pred: int,
__c2pread: int,
__c2pwrite: int,
__errread: int,
__errwrite: int,
Expand All @@ -23,9 +23,9 @@ if sys.platform != "win32":
__restore_signals: int,
__call_setsid: int,
__pgid_to_set: int,
__gid_object: SupportsIndex | None,
__groups_list: list[int] | None,
__uid_object: SupportsIndex | None,
__gid: SupportsIndex | None,
__extra_groups: list[int] | None,
__uid: SupportsIndex | None,
__child_umask: int,
__preexec_fn: Callable[[], None],
__allow_vfork: bool,
Expand Down
8 changes: 6 additions & 2 deletions mypy/typeshed/stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ from collections.abc import Awaitable, Callable, Iterable, Sequence, Set as Abst
from dataclasses import Field
from os import PathLike
from types import FrameType, TracebackType
from typing import Any, AnyStr, ClassVar, Generic, Protocol, TypeVar, overload
from typing_extensions import Buffer, Final, Literal, LiteralString, TypeAlias, final
from typing import Any, AnyStr, ClassVar, Generic, Protocol, SupportsFloat, SupportsInt, TypeVar, overload
from typing_extensions import Buffer, Final, Literal, LiteralString, SupportsIndex, TypeAlias, final

_KT = TypeVar("_KT")
_KT_co = TypeVar("_KT_co", covariant=True)
Expand Down Expand Up @@ -312,3 +312,7 @@ TraceFunction: TypeAlias = Callable[[FrameType, str, Any], TraceFunction | None]
# https://github.com/microsoft/pyright/issues/4339
class DataclassInstance(Protocol):
__dataclass_fields__: ClassVar[dict[str, Field[Any]]]

# Anything that can be passed to the int/float constructors
ConvertibleToInt: TypeAlias = str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc
ConvertibleToFloat: TypeAlias = str | ReadableBuffer | SupportsFloat | SupportsIndex
3 changes: 2 additions & 1 deletion mypy/typeshed/stdlib/abc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class abstractstaticmethod(staticmethod[_P, _R_co]):
class abstractproperty(property):
__isabstractmethod__: Literal[True]

class ABC(metaclass=ABCMeta): ...
class ABC(metaclass=ABCMeta):
__slots__ = ()

def get_cache_token() -> object: ...

Expand Down
8 changes: 8 additions & 0 deletions mypy/typeshed/stdlib/ast.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ class NodeVisitor:
def visit_withitem(self, node: withitem) -> Any: ...
if sys.version_info >= (3, 10):
def visit_Match(self, node: Match) -> Any: ...
def visit_match_case(self, node: match_case) -> Any: ...
def visit_MatchValue(self, node: MatchValue) -> Any: ...
def visit_MatchSequence(self, node: MatchSequence) -> Any: ...
def visit_MatchSingleton(self, node: MatchSingleton) -> Any: ...
def visit_MatchStar(self, node: MatchStar) -> Any: ...
def visit_MatchMapping(self, node: MatchMapping) -> Any: ...
def visit_MatchClass(self, node: MatchClass) -> Any: ...
Expand All @@ -149,6 +151,12 @@ class NodeVisitor:
if sys.version_info >= (3, 11):
def visit_TryStar(self, node: TryStar) -> Any: ...

if sys.version_info >= (3, 12):
def visit_TypeVar(self, node: TypeVar) -> Any: ...
def visit_ParamSpec(self, node: ParamSpec) -> Any: ...
def visit_TypeVarTuple(self, node: TypeVarTuple) -> Any: ...
def visit_TypeAlias(self, node: TypeAlias) -> Any: ...

# visit methods for deprecated nodes
def visit_ExtSlice(self, node: ExtSlice) -> Any: ...
def visit_Index(self, node: Index) -> Any: ...
Expand Down
74 changes: 42 additions & 32 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import types
from _collections_abc import dict_items, dict_keys, dict_values
from _typeshed import (
AnyStr_co,
ConvertibleToFloat,
ConvertibleToInt,
FileDescriptorOrPath,
OpenBinaryMode,
OpenBinaryModeReading,
Expand All @@ -24,7 +26,6 @@ from _typeshed import (
SupportsRDivMod,
SupportsRichComparison,
SupportsRichComparisonT,
SupportsTrunc,
SupportsWrite,
)
from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized
Expand All @@ -48,7 +49,6 @@ from typing import ( # noqa: Y022
SupportsBytes,
SupportsComplex,
SupportsFloat,
SupportsInt,
TypeVar,
overload,
type_check_only,
Expand Down Expand Up @@ -220,7 +220,7 @@ _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026

class int:
@overload
def __new__(cls, __x: str | ReadableBuffer | SupportsInt | SupportsIndex | SupportsTrunc = ...) -> Self: ...
def __new__(cls, __x: ConvertibleToInt = ...) -> Self: ...
@overload
def __new__(cls, __x: str | bytes | bytearray, base: SupportsIndex) -> Self: ...
if sys.version_info >= (3, 8):
Expand Down Expand Up @@ -326,7 +326,7 @@ class int:
def __index__(self) -> int: ...

class float:
def __new__(cls, __x: SupportsFloat | SupportsIndex | str | ReadableBuffer = ...) -> Self: ...
def __new__(cls, __x: ConvertibleToFloat = ...) -> Self: ...
def as_integer_ratio(self) -> tuple[int, int]: ...
def hex(self) -> str: ...
def is_integer(self) -> bool: ...
Expand Down Expand Up @@ -774,7 +774,7 @@ class memoryview(Sequence[int]):
def contiguous(self) -> bool: ...
@property
def nbytes(self) -> int: ...
def __init__(self, obj: ReadableBuffer) -> None: ...
def __new__(cls, obj: ReadableBuffer) -> Self: ...
def __enter__(self) -> Self: ...
def __exit__(
self, __exc_type: type[BaseException] | None, __exc_val: BaseException | None, __exc_tb: TracebackType | None
Expand Down Expand Up @@ -853,9 +853,9 @@ class slice:
@property
def stop(self) -> Any: ...
@overload
def __init__(self, __stop: Any) -> None: ...
def __new__(cls, __stop: Any) -> Self: ...
@overload
def __init__(self, __start: Any, __stop: Any, __step: Any = ...) -> None: ...
def __new__(cls, __start: Any, __stop: Any, __step: Any = ...) -> Self: ...
def __eq__(self, __value: object) -> bool: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def indices(self, __len: SupportsIndex) -> tuple[int, int, int]: ...
Expand Down Expand Up @@ -1110,7 +1110,7 @@ class frozenset(AbstractSet[_T_co], Generic[_T_co]):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...

class enumerate(Iterator[tuple[int, _T]], Generic[_T]):
def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ...
def __new__(cls, iterable: Iterable[_T], start: int = ...) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> tuple[int, _T]: ...
if sys.version_info >= (3, 9):
Expand All @@ -1125,9 +1125,9 @@ class range(Sequence[int]):
@property
def step(self) -> int: ...
@overload
def __init__(self, __stop: SupportsIndex) -> None: ...
def __new__(cls, __stop: SupportsIndex) -> Self: ...
@overload
def __init__(self, __start: SupportsIndex, __stop: SupportsIndex, __step: SupportsIndex = ...) -> None: ...
def __new__(cls, __start: SupportsIndex, __stop: SupportsIndex, __step: SupportsIndex = ...) -> Self: ...
def count(self, __value: int) -> int: ...
def index(self, __value: int) -> int: ... # type: ignore[override]
def __len__(self) -> int: ...
Expand Down Expand Up @@ -1320,11 +1320,11 @@ def exit(code: sys._ExitCode = None) -> NoReturn: ...

class filter(Iterator[_T], Generic[_T]):
@overload
def __init__(self, __function: None, __iterable: Iterable[_T | None]) -> None: ...
def __new__(cls, __function: None, __iterable: Iterable[_T | None]) -> Self: ...
@overload
def __init__(self, __function: Callable[[_S], TypeGuard[_T]], __iterable: Iterable[_S]) -> None: ...
def __new__(cls, __function: Callable[[_S], TypeGuard[_T]], __iterable: Iterable[_S]) -> Self: ...
@overload
def __init__(self, __function: Callable[[_T], Any], __iterable: Iterable[_T]) -> None: ...
def __new__(cls, __function: Callable[[_T], Any], __iterable: Iterable[_T]) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _T: ...

Expand Down Expand Up @@ -1379,35 +1379,35 @@ def locals() -> dict[str, Any]: ...

class map(Iterator[_S], Generic[_S]):
@overload
def __init__(self, __func: Callable[[_T1], _S], __iter1: Iterable[_T1]) -> None: ...
def __new__(cls, __func: Callable[[_T1], _S], __iter1: Iterable[_T1]) -> Self: ...
@overload
def __init__(self, __func: Callable[[_T1, _T2], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> None: ...
def __new__(cls, __func: Callable[[_T1, _T2], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2]) -> Self: ...
@overload
def __init__(
self, __func: Callable[[_T1, _T2, _T3], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]
) -> None: ...
def __new__(
cls, __func: Callable[[_T1, _T2, _T3], _S], __iter1: Iterable[_T1], __iter2: Iterable[_T2], __iter3: Iterable[_T3]
) -> Self: ...
@overload
def __init__(
self,
def __new__(
cls,
__func: Callable[[_T1, _T2, _T3, _T4], _S],
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
) -> None: ...
) -> Self: ...
@overload
def __init__(
self,
def __new__(
cls,
__func: Callable[[_T1, _T2, _T3, _T4, _T5], _S],
__iter1: Iterable[_T1],
__iter2: Iterable[_T2],
__iter3: Iterable[_T3],
__iter4: Iterable[_T4],
__iter5: Iterable[_T5],
) -> None: ...
) -> Self: ...
@overload
def __init__(
self,
def __new__(
cls,
__func: Callable[..., _S],
__iter1: Iterable[Any],
__iter2: Iterable[Any],
Expand All @@ -1416,7 +1416,7 @@ class map(Iterator[_S], Generic[_S]):
__iter5: Iterable[Any],
__iter6: Iterable[Any],
*iterables: Iterable[Any],
) -> None: ...
) -> Self: ...
def __iter__(self) -> Self: ...
def __next__(self) -> _S: ...

Expand Down Expand Up @@ -1725,6 +1725,8 @@ def vars(__object: Any = ...) -> dict[str, Any]: ...

class zip(Iterator[_T_co], Generic[_T_co]):
if sys.version_info >= (3, 10):
@overload
def __new__(cls, *, strict: bool = ...) -> zip[Any]: ...
@overload
def __new__(cls, __iter1: Iterable[_T1], *, strict: bool = ...) -> zip[tuple[_T1]]: ...
@overload
Expand Down Expand Up @@ -1767,6 +1769,8 @@ class zip(Iterator[_T_co], Generic[_T_co]):
strict: bool = ...,
) -> zip[tuple[Any, ...]]: ...
else:
@overload
def __new__(cls) -> zip[Any]: ...
@overload
def __new__(cls, __iter1: Iterable[_T1]) -> zip[tuple[_T1]]: ...
@overload
Expand Down Expand Up @@ -1812,11 +1816,17 @@ def __import__(
) -> types.ModuleType: ...
def __build_class__(__func: Callable[[], _Cell | Any], __name: str, *bases: Any, metaclass: Any = ..., **kwds: Any) -> Any: ...

# Actually the type of Ellipsis is <type 'ellipsis'>, but since it's
# not exposed anywhere under that name, we make it private here.
@final
@type_check_only
class ellipsis: ...
if sys.version_info >= (3, 10):
# In Python 3.10, EllipsisType is exposed publicly in the types module.
@final
class ellipsis: ...

else:
# Actually the type of Ellipsis is <type 'ellipsis'>, but since it's
# not exposed anywhere under that name, we make it private here.
@final
@type_check_only
class ellipsis: ...

Ellipsis: ellipsis

Expand Down
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/codecs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ class _Stream(_WritableStream, _ReadableStream, Protocol): ...
# They were much more common in Python 2 than in Python 3.

class _Encoder(Protocol):
def __call__(self, input: str, errors: str = ...) -> tuple[bytes, int]: ... # signature of Codec().encode
def __call__(self, __input: str, __errors: str = ...) -> tuple[bytes, int]: ... # signature of Codec().encode

class _Decoder(Protocol):
def __call__(self, input: bytes, errors: str = ...) -> tuple[str, int]: ... # signature of Codec().decode
def __call__(self, __input: bytes, __errors: str = ...) -> tuple[str, int]: ... # signature of Codec().decode

class _StreamReader(Protocol):
def __call__(self, stream: _ReadableStream, errors: str = ...) -> StreamReader: ...
def __call__(self, __stream: _ReadableStream, __errors: str = ...) -> StreamReader: ...

class _StreamWriter(Protocol):
def __call__(self, stream: _WritableStream, errors: str = ...) -> StreamWriter: ...
def __call__(self, __stream: _WritableStream, __errors: str = ...) -> StreamWriter: ...

class _IncrementalEncoder(Protocol):
def __call__(self, errors: str = ...) -> IncrementalEncoder: ...
Expand Down
9 changes: 9 additions & 0 deletions mypy/typeshed/stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
@overload
def setdefault(self, key: _KT, default: _VT) -> _VT: ...
def __eq__(self, __value: object) -> bool: ...
if sys.version_info >= (3, 9):
@overload
def __or__(self, __value: dict[_KT, _VT]) -> Self: ...
@overload
def __or__(self, __value: dict[_T1, _T2]) -> OrderedDict[_KT | _T1, _VT | _T2]: ...
@overload
def __ror__(self, __value: dict[_KT, _VT]) -> Self: ...
@overload
def __ror__(self, __value: dict[_T1, _T2]) -> OrderedDict[_KT | _T1, _VT | _T2]: ... # type: ignore[misc]

class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]):
default_factory: Callable[[], _VT] | None
Expand Down
5 changes: 5 additions & 0 deletions mypy/typeshed/stdlib/fcntl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ if sys.platform != "win32":
I_STR: int
I_SWROPT: int
I_UNLINK: int

if sys.version_info >= (3, 12) and sys.platform == "linux":
FICLONE: int
FICLONERANGE: int

@overload
def fcntl(__fd: FileDescriptorLike, __cmd: int, __arg: int = 0) -> int: ...
@overload
Expand Down
1 change: 1 addition & 0 deletions mypy/typeshed/stdlib/http/server.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
extensions_map: dict[str, str]
if sys.version_info >= (3, 12):
index_pages: ClassVar[tuple[str, ...]]
directory: str
def __init__(
self,
request: socketserver._RequestType,
Expand Down
Loading

0 comments on commit 7a62481

Please sign in to comment.