Skip to content

Commit

Permalink
Sync typeshed
Browse files Browse the repository at this point in the history
  • Loading branch information
mypybot committed Sep 1, 2023
1 parent df4717e commit 66f2153
Show file tree
Hide file tree
Showing 21 changed files with 359 additions and 103 deletions.
12 changes: 8 additions & 4 deletions mypy/typeshed/stdlib/_ctypes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class _CData(metaclass=_CDataMeta):
def __buffer__(self, __flags: int) -> memoryview: ...
def __release_buffer__(self, __buffer: memoryview) -> None: ...

class _SimpleCData(Generic[_T], _CData):
class _SimpleCData(_CData, Generic[_T]):
value: _T
# The TypeVar can be unsolved here,
# but we can't use overloads without creating many, many mypy false-positive errors
Expand All @@ -78,7 +78,7 @@ class _SimpleCData(Generic[_T], _CData):
class _CanCastTo(_CData): ...
class _PointerLike(_CanCastTo): ...

class _Pointer(Generic[_CT], _PointerLike, _CData):
class _Pointer(_PointerLike, _CData, Generic[_CT]):
_type_: type[_CT]
contents: _CT
@overload
Expand Down Expand Up @@ -140,7 +140,7 @@ class _StructUnionBase(_CData, metaclass=_StructUnionMeta):
class Union(_StructUnionBase): ...
class Structure(_StructUnionBase): ...

class Array(Generic[_CT], _CData):
class Array(_CData, Generic[_CT]):
@property
@abstractmethod
def _length_(self) -> int: ...
Expand All @@ -151,7 +151,11 @@ class Array(Generic[_CT], _CData):
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
7 changes: 6 additions & 1 deletion mypy/typeshed/stdlib/asyncio/taskgroups.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import sys
from contextvars import Context
from types import TracebackType
from typing import TypeVar
from typing import Any, TypeVar
from typing_extensions import Self

from . import _CoroutineLike
from .events import AbstractEventLoop
from .tasks import Task

if sys.version_info >= (3, 12):
Expand All @@ -15,6 +16,10 @@ else:
_T = TypeVar("_T")

class TaskGroup:
_loop: AbstractEventLoop | None
_tasks: set[Task[Any]]

async def __aenter__(self) -> Self: ...
async def __aexit__(self, et: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ...
def create_task(self, coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None) -> Task[_T]: ...
def _on_task_done(self, task: Task[object]) -> None: ...
30 changes: 21 additions & 9 deletions mypy/typeshed/stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,6 @@ if sys.version_info >= (3, 10):
async def sleep(delay: float) -> None: ...
@overload
async def sleep(delay: float, result: _T) -> _T: ...
@overload
async def wait(fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED") -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
@overload
async def wait(
fs: Iterable[Awaitable[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
async def wait_for(fut: _FutureLike[_T], timeout: float | None) -> _T: ...

else:
Expand All @@ -257,6 +251,25 @@ else:
async def sleep(delay: float, *, loop: AbstractEventLoop | None = None) -> None: ...
@overload
async def sleep(delay: float, result: _T, *, loop: AbstractEventLoop | None = None) -> _T: ...
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = None) -> _T: ...

if sys.version_info >= (3, 11):
@overload
async def wait(fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED") -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
@overload
async def wait(
fs: Iterable[Task[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...

elif sys.version_info >= (3, 10):
@overload
async def wait(fs: Iterable[_FT], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED") -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
@overload
async def wait(
fs: Iterable[Awaitable[_T]], *, timeout: float | None = None, return_when: str = "ALL_COMPLETED"
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...

else:
@overload
async def wait( # type: ignore[misc]
fs: Iterable[_FT],
Expand All @@ -273,7 +286,6 @@ else:
timeout: float | None = None,
return_when: str = "ALL_COMPLETED",
) -> tuple[set[Task[_T]], set[Task[_T]]]: ...
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = None) -> _T: ...

if sys.version_info >= (3, 12):
_TaskCompatibleCoro: TypeAlias = Coroutine[Any, Any, _T_co]
Expand All @@ -291,7 +303,7 @@ class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright:
coro: _TaskCompatibleCoro[_T_co],
*,
loop: AbstractEventLoop = ...,
name: str | None,
name: str | None = ...,
context: Context | None = None,
eager_start: bool = False,
) -> None: ...
Expand All @@ -301,7 +313,7 @@ class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright:
coro: _TaskCompatibleCoro[_T_co],
*,
loop: AbstractEventLoop = ...,
name: str | None,
name: str | None = ...,
context: Context | None = None,
) -> None: ...
elif sys.version_info >= (3, 8):
Expand Down
97 changes: 95 additions & 2 deletions mypy/typeshed/stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ from typing import ( # noqa: Y022
from typing_extensions import (
Concatenate,
Literal,
LiteralString,
ParamSpec,
Self,
SupportsIndex,
Expand Down Expand Up @@ -441,20 +442,38 @@ 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, x: 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: ...
if sys.version_info >= (3, 8):
@overload
def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ...
@overload
def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc]
else:
@overload
def expandtabs(self: LiteralString, tabsize: int = 8) -> LiteralString: ...
@overload
def expandtabs(self, tabsize: int = 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, map: _FormatMapMapping) -> str: ...
def index(self, __sub: str, __start: SupportsIndex | None = ..., __end: SupportsIndex | None = ...) -> int: ...
Expand All @@ -470,32 +489,91 @@ 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]
@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 @@ -506,6 +584,9 @@ 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]
Expand All @@ -514,13 +595,25 @@ class str(Sequence[str]):
def __getitem__(self, __key: SupportsIndex | slice) -> str: ...
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 @@ -1698,11 +1791,11 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit
# Instead, we special-case the most common examples of this: bool and literal integers.
if sys.version_info >= (3, 8):
@overload
def sum(__iterable: Iterable[bool], start: int = 0) -> int: ... # type: ignore[misc]
def sum(__iterable: Iterable[bool | _LiteralInteger], start: int = 0) -> int: ... # type: ignore[misc]

else:
@overload
def sum(__iterable: Iterable[bool], __start: int = 0) -> int: ... # type: ignore[misc]
def sum(__iterable: Iterable[bool | _LiteralInteger], __start: int = 0) -> int: ... # type: ignore[misc]

@overload
def sum(__iterable: Iterable[_SupportsSumNoDefaultT]) -> _SupportsSumNoDefaultT | Literal[0]: ...
Expand Down

0 comments on commit 66f2153

Please sign in to comment.