mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 21:14:48 +08:00
Add more defaults to the stdlib (#9606)
Continuing work towards #8988. The first five commits were created using stubdefaulter on various Python versions; the following commits were all created manually by me to fix various problems. The main things this adds that weren't present in #9501 are: - Defaults in Windows-only modules and Windows-only branches (because I'm running a Windows machine) - Defaults in non-py311 branches - Defaults for float parameters - Defaults for overloads
This commit is contained in:
@@ -55,13 +55,13 @@ if sys.version_info >= (3, 10):
|
||||
|
||||
else:
|
||||
def as_completed(
|
||||
fs: Iterable[_FutureLike[_T]], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ...
|
||||
fs: Iterable[_FutureLike[_T]], *, loop: AbstractEventLoop | None = None, timeout: float | None = None
|
||||
) -> Iterator[Future[_T]]: ...
|
||||
|
||||
@overload
|
||||
def ensure_future(coro_or_future: _FT, *, loop: AbstractEventLoop | None = ...) -> _FT: ... # type: ignore[misc]
|
||||
def ensure_future(coro_or_future: _FT, *, loop: AbstractEventLoop | None = None) -> _FT: ... # type: ignore[misc]
|
||||
@overload
|
||||
def ensure_future(coro_or_future: Awaitable[_T], *, loop: AbstractEventLoop | None = ...) -> Task[_T]: ...
|
||||
def ensure_future(coro_or_future: Awaitable[_T], *, loop: AbstractEventLoop | None = None) -> Task[_T]: ...
|
||||
|
||||
# `gather()` actually returns a list with length equal to the number
|
||||
# of tasks passed; however, Tuple is used similar to the annotation for
|
||||
@@ -72,10 +72,10 @@ def ensure_future(coro_or_future: Awaitable[_T], *, loop: AbstractEventLoop | No
|
||||
# but having overlapping overloads is the only way to get acceptable type inference in all edge cases.
|
||||
if sys.version_info >= (3, 10):
|
||||
@overload
|
||||
def gather(__coro_or_future1: _FutureLike[_T1], *, return_exceptions: Literal[False] = ...) -> Future[tuple[_T1]]: ... # type: ignore[misc]
|
||||
def gather(__coro_or_future1: _FutureLike[_T1], *, return_exceptions: Literal[False] = False) -> Future[tuple[_T1]]: ... # type: ignore[misc]
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
__coro_or_future1: _FutureLike[_T1], __coro_or_future2: _FutureLike[_T2], *, return_exceptions: Literal[False] = ...
|
||||
__coro_or_future1: _FutureLike[_T1], __coro_or_future2: _FutureLike[_T2], *, return_exceptions: Literal[False] = False
|
||||
) -> Future[tuple[_T1, _T2]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
@@ -83,7 +83,7 @@ if sys.version_info >= (3, 10):
|
||||
__coro_or_future2: _FutureLike[_T2],
|
||||
__coro_or_future3: _FutureLike[_T3],
|
||||
*,
|
||||
return_exceptions: Literal[False] = ...,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
@@ -92,7 +92,7 @@ if sys.version_info >= (3, 10):
|
||||
__coro_or_future3: _FutureLike[_T3],
|
||||
__coro_or_future4: _FutureLike[_T4],
|
||||
*,
|
||||
return_exceptions: Literal[False] = ...,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3, _T4]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
@@ -102,7 +102,7 @@ if sys.version_info >= (3, 10):
|
||||
__coro_or_future4: _FutureLike[_T4],
|
||||
__coro_or_future5: _FutureLike[_T5],
|
||||
*,
|
||||
return_exceptions: Literal[False] = ...,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ...
|
||||
@overload
|
||||
def gather(__coro_or_future1: _FutureLike[_T1], *, return_exceptions: bool) -> Future[tuple[_T1 | BaseException]]: ... # type: ignore[misc]
|
||||
@@ -140,20 +140,20 @@ if sys.version_info >= (3, 10):
|
||||
tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException]
|
||||
]: ...
|
||||
@overload
|
||||
def gather(*coros_or_futures: _FutureLike[Any], return_exceptions: bool = ...) -> Future[list[Any]]: ... # type: ignore[misc]
|
||||
def gather(*coros_or_futures: _FutureLike[Any], return_exceptions: bool = False) -> Future[list[Any]]: ... # type: ignore[misc]
|
||||
|
||||
else:
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
__coro_or_future1: _FutureLike[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ...
|
||||
__coro_or_future1: _FutureLike[_T1], *, loop: AbstractEventLoop | None = None, return_exceptions: Literal[False] = False
|
||||
) -> Future[tuple[_T1]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
__coro_or_future1: _FutureLike[_T1],
|
||||
__coro_or_future2: _FutureLike[_T2],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = ...,
|
||||
return_exceptions: Literal[False] = ...,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
@@ -161,8 +161,8 @@ else:
|
||||
__coro_or_future2: _FutureLike[_T2],
|
||||
__coro_or_future3: _FutureLike[_T3],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = ...,
|
||||
return_exceptions: Literal[False] = ...,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
@@ -171,8 +171,8 @@ else:
|
||||
__coro_or_future3: _FutureLike[_T3],
|
||||
__coro_or_future4: _FutureLike[_T4],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = ...,
|
||||
return_exceptions: Literal[False] = ...,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3, _T4]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
@@ -182,19 +182,19 @@ else:
|
||||
__coro_or_future4: _FutureLike[_T4],
|
||||
__coro_or_future5: _FutureLike[_T5],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = ...,
|
||||
return_exceptions: Literal[False] = ...,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: Literal[False] = False,
|
||||
) -> Future[tuple[_T1, _T2, _T3, _T4, _T5]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
__coro_or_future1: _FutureLike[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool
|
||||
__coro_or_future1: _FutureLike[_T1], *, loop: AbstractEventLoop | None = None, return_exceptions: bool
|
||||
) -> Future[tuple[_T1 | BaseException]]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
__coro_or_future1: _FutureLike[_T1],
|
||||
__coro_or_future2: _FutureLike[_T2],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = ...,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: bool,
|
||||
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException]]: ...
|
||||
@overload
|
||||
@@ -203,7 +203,7 @@ else:
|
||||
__coro_or_future2: _FutureLike[_T2],
|
||||
__coro_or_future3: _FutureLike[_T3],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = ...,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: bool,
|
||||
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException]]: ...
|
||||
@overload
|
||||
@@ -213,7 +213,7 @@ else:
|
||||
__coro_or_future3: _FutureLike[_T3],
|
||||
__coro_or_future4: _FutureLike[_T4],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = ...,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: bool,
|
||||
) -> Future[tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException]]: ...
|
||||
@overload
|
||||
@@ -224,14 +224,14 @@ else:
|
||||
__coro_or_future4: _FutureLike[_T4],
|
||||
__coro_or_future5: _FutureLike[_T5],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = ...,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
return_exceptions: bool,
|
||||
) -> Future[
|
||||
tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException]
|
||||
]: ...
|
||||
@overload
|
||||
def gather( # type: ignore[misc]
|
||||
*coros_or_futures: _FutureLike[Any], loop: AbstractEventLoop | None = ..., return_exceptions: bool = ...
|
||||
*coros_or_futures: _FutureLike[Any], loop: AbstractEventLoop | None = None, return_exceptions: bool = False
|
||||
) -> Future[list[Any]]: ...
|
||||
|
||||
def run_coroutine_threadsafe(coro: _FutureLike[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...
|
||||
@@ -243,28 +243,36 @@ if sys.version_info >= (3, 10):
|
||||
@overload
|
||||
async def sleep(delay: float, result: _T) -> _T: ...
|
||||
@overload
|
||||
async def wait(fs: Iterable[_FT], *, timeout: float | None = ..., return_when: str = ...) -> tuple[set[_FT], set[_FT]]: ... # type: ignore[misc]
|
||||
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 = ..., return_when: str = ...
|
||||
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:
|
||||
def shield(arg: _FutureLike[_T], *, loop: AbstractEventLoop | None = ...) -> Future[_T]: ...
|
||||
def shield(arg: _FutureLike[_T], *, loop: AbstractEventLoop | None = None) -> Future[_T]: ...
|
||||
@overload
|
||||
async def sleep(delay: float, *, loop: AbstractEventLoop | None = ...) -> None: ...
|
||||
async def sleep(delay: float, *, loop: AbstractEventLoop | None = None) -> None: ...
|
||||
@overload
|
||||
async def sleep(delay: float, result: _T, *, loop: AbstractEventLoop | None = ...) -> _T: ...
|
||||
async def sleep(delay: float, result: _T, *, loop: AbstractEventLoop | None = None) -> _T: ...
|
||||
@overload
|
||||
async def wait( # type: ignore[misc]
|
||||
fs: Iterable[_FT], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ..., return_when: str = ...
|
||||
fs: Iterable[_FT],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
timeout: float | None = None,
|
||||
return_when: str = "ALL_COMPLETED",
|
||||
) -> tuple[set[_FT], set[_FT]]: ...
|
||||
@overload
|
||||
async def wait(
|
||||
fs: Iterable[Awaitable[_T]], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ..., return_when: str = ...
|
||||
fs: Iterable[Awaitable[_T]],
|
||||
*,
|
||||
loop: AbstractEventLoop | None = None,
|
||||
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 = ...) -> _T: ...
|
||||
async def wait_for(fut: _FutureLike[_T], timeout: float | None, *, loop: AbstractEventLoop | None = None) -> _T: ...
|
||||
|
||||
# mypy and pyright complain that a subclass of an invariant class shouldn't be covariant.
|
||||
# While this is true in general, here it's sort-of okay to have a covariant subclass,
|
||||
@@ -295,9 +303,9 @@ class Task(Future[_T_co], Generic[_T_co]): # type: ignore[type-var] # pyright:
|
||||
def uncancel(self) -> int: ...
|
||||
if sys.version_info < (3, 9):
|
||||
@classmethod
|
||||
def current_task(cls, loop: AbstractEventLoop | None = ...) -> Task[Any] | None: ...
|
||||
def current_task(cls, loop: AbstractEventLoop | None = None) -> Task[Any] | None: ...
|
||||
@classmethod
|
||||
def all_tasks(cls, loop: AbstractEventLoop | None = ...) -> set[Task[Any]]: ...
|
||||
def all_tasks(cls, loop: AbstractEventLoop | None = None) -> set[Task[Any]]: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
||||
|
||||
@@ -309,7 +317,7 @@ if sys.version_info >= (3, 11):
|
||||
) -> Task[_T]: ...
|
||||
|
||||
elif sys.version_info >= (3, 8):
|
||||
def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = ...) -> Task[_T]: ...
|
||||
def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = None) -> Task[_T]: ...
|
||||
|
||||
else:
|
||||
def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T]) -> Task[_T]: ...
|
||||
|
||||
Reference in New Issue
Block a user