Skip to content

Sync typeshed #16121

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 6 commits into from
Sep 16, 2023
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
2 changes: 1 addition & 1 deletion mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,7 @@ def get_importable_stdlib_modules() -> set[str]:
modules_by_finder[m.module_finder].add(m.name)
for finder, module_group in modules_by_finder.items():
if (
"site-packages" not in Path(finder.path).parents
"site-packages" not in Path(finder.path).parts
# if "_queue" is present, it's most likely the module finder
# for stdlib extension modules;
# if "queue" is present, it's most likely the module finder
Expand Down
12 changes: 10 additions & 2 deletions mypy/typeshed/stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,23 @@ class CFuncPtr(_PointerLike, _CData):

def __call__(self, *args: Any, **kwargs: Any) -> Any: ...

class _CField:
_GetT = TypeVar("_GetT")
_SetT = TypeVar("_SetT")

class _CField(Generic[_CT, _GetT, _SetT]):
offset: int
size: int
@overload
def __get__(self, __instance: None, __owner: type[Any] | None) -> Self: ...
@overload
def __get__(self, __instance: Any, __owner: type[Any] | None) -> _GetT: ...
def __set__(self, __instance: Any, __value: _SetT) -> None: ...

class _StructUnionMeta(_CDataMeta):
_fields_: Sequence[tuple[str, type[_CData]] | tuple[str, type[_CData], int]]
_pack_: int
_anonymous_: Sequence[str]
def __getattr__(self, name: str) -> _CField: ...
def __getattr__(self, name: str) -> _CField[Any, Any, Any]: ...

class _StructUnionBase(_CData, metaclass=_StructUnionMeta):
def __init__(self, *args: Any, **kw: Any) -> None: ...
Expand Down
105 changes: 83 additions & 22 deletions mypy/typeshed/stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import concurrent.futures
import sys
from collections.abc import Awaitable, Coroutine, Generator, Iterable, Iterator
from types import FrameType
from typing import Any, Generic, TextIO, TypeVar, overload
from typing import Any, Generic, Protocol, TextIO, TypeVar, overload
from typing_extensions import Literal, TypeAlias

from . import _CoroutineLike
Expand All @@ -14,27 +14,52 @@ if sys.version_info >= (3, 9):
if sys.version_info >= (3, 11):
from contextvars import Context

__all__ = (
"Task",
"create_task",
"FIRST_COMPLETED",
"FIRST_EXCEPTION",
"ALL_COMPLETED",
"wait",
"wait_for",
"as_completed",
"sleep",
"gather",
"shield",
"ensure_future",
"run_coroutine_threadsafe",
"current_task",
"all_tasks",
"_register_task",
"_unregister_task",
"_enter_task",
"_leave_task",
)
if sys.version_info >= (3, 12):
__all__ = (
"Task",
"create_task",
"FIRST_COMPLETED",
"FIRST_EXCEPTION",
"ALL_COMPLETED",
"wait",
"wait_for",
"as_completed",
"sleep",
"gather",
"shield",
"ensure_future",
"run_coroutine_threadsafe",
"current_task",
"all_tasks",
"create_eager_task_factory",
"eager_task_factory",
"_register_task",
"_unregister_task",
"_enter_task",
"_leave_task",
)
else:
__all__ = (
"Task",
"create_task",
"FIRST_COMPLETED",
"FIRST_EXCEPTION",
"ALL_COMPLETED",
"wait",
"wait_for",
"as_completed",
"sleep",
"gather",
"shield",
"ensure_future",
"run_coroutine_threadsafe",
"current_task",
"all_tasks",
"_register_task",
"_unregister_task",
"_enter_task",
"_leave_task",
)

_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
Expand Down Expand Up @@ -356,5 +381,41 @@ else:
def current_task(loop: AbstractEventLoop | None = None) -> Task[Any] | None: ...
def _enter_task(loop: AbstractEventLoop, task: Task[Any]) -> None: ...
def _leave_task(loop: AbstractEventLoop, task: Task[Any]) -> None: ...

if sys.version_info >= (3, 12):
_TaskT_co = TypeVar("_TaskT_co", bound=Task[Any], covariant=True)

class _CustomTaskConstructor(Protocol[_TaskT_co]):
def __call__(
self,
__coro: _TaskCompatibleCoro[Any],
*,
loop: AbstractEventLoop,
name: str | None,
context: Context | None,
eager_start: bool,
) -> _TaskT_co: ...

class _EagerTaskFactoryType(Protocol[_TaskT_co]):
def __call__(
self,
loop: AbstractEventLoop,
coro: _TaskCompatibleCoro[Any],
*,
name: str | None = None,
context: Context | None = None,
) -> _TaskT_co: ...

def create_eager_task_factory(
custom_task_constructor: _CustomTaskConstructor[_TaskT_co],
) -> _EagerTaskFactoryType[_TaskT_co]: ...
def eager_task_factory(
loop: AbstractEventLoop | None,
coro: _TaskCompatibleCoro[_T_co],
*,
name: str | None = None,
context: Context | None = None,
) -> Task[_T_co]: ...

def _register_task(task: Task[Any]) -> None: ...
def _unregister_task(task: Task[Any]) -> None: ...
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1027,13 +1027,13 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
if sys.version_info >= (3, 9):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...
@overload
def __or__(self, __value: Mapping[_KT, _VT]) -> dict[_KT, _VT]: ...
def __or__(self, __value: dict[_KT, _VT]) -> dict[_KT, _VT]: ...
@overload
def __or__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
def __or__(self, __value: dict[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
@overload
def __ror__(self, __value: Mapping[_KT, _VT]) -> dict[_KT, _VT]: ...
def __ror__(self, __value: dict[_KT, _VT]) -> dict[_KT, _VT]: ...
@overload
def __ror__(self, __value: Mapping[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
def __ror__(self, __value: dict[_T1, _T2]) -> dict[_KT | _T1, _VT | _T2]: ...
# dict.__ior__ should be kept roughly in line with MutableMapping.update()
@overload # type: ignore[misc]
def __ior__(self, __value: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ...
Expand Down
17 changes: 13 additions & 4 deletions mypy/typeshed/stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ...
@overload
def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ...
if sys.version_info >= (3, 12):
@overload
def get(self, key: _KT, default: None = None) -> _VT | None: ...
@overload
def get(self, key: _KT, default: _T) -> _VT | _T: ...

class UserList(MutableSequence[_T]):
data: list[_T]
Expand Down Expand Up @@ -402,13 +407,13 @@ class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]):
def copy(self) -> Self: ...
if sys.version_info >= (3, 9):
@overload
def __or__(self, __value: Mapping[_KT, _VT]) -> Self: ...
def __or__(self, __value: dict[_KT, _VT]) -> Self: ...
@overload
def __or__(self, __value: Mapping[_T1, _T2]) -> defaultdict[_KT | _T1, _VT | _T2]: ...
def __or__(self, __value: dict[_T1, _T2]) -> defaultdict[_KT | _T1, _VT | _T2]: ...
@overload
def __ror__(self, __value: Mapping[_KT, _VT]) -> Self: ...
def __ror__(self, __value: dict[_KT, _VT]) -> Self: ...
@overload
def __ror__(self, __value: Mapping[_T1, _T2]) -> defaultdict[_KT | _T1, _VT | _T2]: ...
def __ror__(self, __value: dict[_T1, _T2]) -> defaultdict[_KT | _T1, _VT | _T2]: ... # type: ignore[misc]

class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
maps: list[MutableMapping[_KT, _VT]]
Expand All @@ -422,6 +427,10 @@ class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
def __iter__(self) -> Iterator[_KT]: ...
def __len__(self) -> int: ...
def __contains__(self, key: object) -> bool: ...
@overload
def get(self, key: _KT, default: None = None) -> _VT | None: ...
@overload
def get(self, key: _KT, default: _T) -> _VT | _T: ...
def __missing__(self, key: _KT) -> _VT: ... # undocumented
def __bool__(self) -> bool: ...
# Keep ChainMap.setdefault in line with MutableMapping.setdefault, modulo positional-only differences.
Expand Down
8 changes: 4 additions & 4 deletions mypy/typeshed/stdlib/csv.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class unix_dialect(Dialect): ...

class DictReader(Iterator[_DictReadMapping[_T | Any, str | Any]], Generic[_T]):
fieldnames: Sequence[_T] | None
restkey: str | None
restval: str | None
restkey: _T | None
restval: str | Any | None
reader: _reader
dialect: _DialectLike
line_num: int
Expand All @@ -81,8 +81,8 @@ class DictReader(Iterator[_DictReadMapping[_T | Any, str | Any]], Generic[_T]):
self,
f: Iterable[str],
fieldnames: Sequence[_T],
restkey: str | None = None,
restval: str | None = None,
restkey: _T | None = None,
restval: str | Any | None = None,
dialect: _DialectLike = "excel",
*,
delimiter: str = ",",
Expand Down
89 changes: 47 additions & 42 deletions mypy/typeshed/stdlib/ctypes/wintypes.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ctypes import (
Array,
Structure,
_CField,
_Pointer,
_SimpleCData,
c_byte,
Expand All @@ -20,6 +21,7 @@ from ctypes import (
c_wchar,
c_wchar_p,
)
from typing import TypeVar
from typing_extensions import TypeAlias

BYTE = c_byte
Expand Down Expand Up @@ -101,85 +103,88 @@ HWND = HANDLE
SC_HANDLE = HANDLE
SERVICE_STATUS_HANDLE = HANDLE

_CIntLikeT = TypeVar("_CIntLikeT", bound=_SimpleCData[int])
_CIntLikeField: TypeAlias = _CField[_CIntLikeT, int, _CIntLikeT | int]

class RECT(Structure):
left: LONG
top: LONG
right: LONG
bottom: LONG
left: _CIntLikeField[LONG]
top: _CIntLikeField[LONG]
right: _CIntLikeField[LONG]
bottom: _CIntLikeField[LONG]

RECTL = RECT
_RECTL = RECT
tagRECT = RECT

class _SMALL_RECT(Structure):
Left: SHORT
Top: SHORT
Right: SHORT
Bottom: SHORT
Left: _CIntLikeField[SHORT]
Top: _CIntLikeField[SHORT]
Right: _CIntLikeField[SHORT]
Bottom: _CIntLikeField[SHORT]

SMALL_RECT = _SMALL_RECT

class _COORD(Structure):
X: SHORT
Y: SHORT
X: _CIntLikeField[SHORT]
Y: _CIntLikeField[SHORT]

class POINT(Structure):
x: LONG
y: LONG
x: _CIntLikeField[LONG]
y: _CIntLikeField[LONG]

POINTL = POINT
_POINTL = POINT
tagPOINT = POINT

class SIZE(Structure):
cx: LONG
cy: LONG
cx: _CIntLikeField[LONG]
cy: _CIntLikeField[LONG]

SIZEL = SIZE
tagSIZE = SIZE

def RGB(red: int, green: int, blue: int) -> int: ...

class FILETIME(Structure):
dwLowDateTime: DWORD
dwHighDateTime: DWORD
dwLowDateTime: _CIntLikeField[DWORD]
dwHighDateTime: _CIntLikeField[DWORD]

_FILETIME = FILETIME

class MSG(Structure):
hWnd: HWND
message: UINT
wParam: WPARAM
lParam: LPARAM
time: DWORD
pt: POINT
hWnd: _CField[HWND, int | None, HWND | int | None]
message: _CIntLikeField[UINT]
wParam: _CIntLikeField[WPARAM]
lParam: _CIntLikeField[LPARAM]
time: _CIntLikeField[DWORD]
pt: _CField[POINT, POINT, POINT]

tagMSG = MSG
MAX_PATH: int

class WIN32_FIND_DATAA(Structure):
dwFileAttributes: DWORD
ftCreationTime: FILETIME
ftLastAccessTime: FILETIME
ftLastWriteTime: FILETIME
nFileSizeHigh: DWORD
nFileSizeLow: DWORD
dwReserved0: DWORD
dwReserved1: DWORD
cFileName: Array[CHAR]
cAlternateFileName: Array[CHAR]
dwFileAttributes: _CIntLikeField[DWORD]
ftCreationTime: _CField[FILETIME, FILETIME, FILETIME]
ftLastAccessTime: _CField[FILETIME, FILETIME, FILETIME]
ftLastWriteTime: _CField[FILETIME, FILETIME, FILETIME]
nFileSizeHigh: _CIntLikeField[DWORD]
nFileSizeLow: _CIntLikeField[DWORD]
dwReserved0: _CIntLikeField[DWORD]
dwReserved1: _CIntLikeField[DWORD]
cFileName: _CField[Array[CHAR], bytes, bytes]
cAlternateFileName: _CField[Array[CHAR], bytes, bytes]

class WIN32_FIND_DATAW(Structure):
dwFileAttributes: DWORD
ftCreationTime: FILETIME
ftLastAccessTime: FILETIME
ftLastWriteTime: FILETIME
nFileSizeHigh: DWORD
nFileSizeLow: DWORD
dwReserved0: DWORD
dwReserved1: DWORD
cFileName: Array[WCHAR]
cAlternateFileName: Array[WCHAR]
dwFileAttributes: _CIntLikeField[DWORD]
ftCreationTime: _CField[FILETIME, FILETIME, FILETIME]
ftLastAccessTime: _CField[FILETIME, FILETIME, FILETIME]
ftLastWriteTime: _CField[FILETIME, FILETIME, FILETIME]
nFileSizeHigh: _CIntLikeField[DWORD]
nFileSizeLow: _CIntLikeField[DWORD]
dwReserved0: _CIntLikeField[DWORD]
dwReserved1: _CIntLikeField[DWORD]
cFileName: _CField[Array[WCHAR], str, str]
cAlternateFileName: _CField[Array[WCHAR], str, str]

# These pointer type definitions use _Pointer[...] instead of POINTER(...), to allow them
# to be used in type annotations.
Expand Down
Loading