Skip to content

Use new union syntax in rest of stdlib #5884

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 4 commits into from
Aug 8, 2021
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
8 changes: 4 additions & 4 deletions stdlib/_thread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LockType:
def locked(self) -> bool: ...
def __enter__(self) -> bool: ...
def __exit__(
self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]
self, type: Type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None
) -> None: ...

def start_new_thread(function: Callable[..., Any], args: Tuple[Any, ...], kwargs: Dict[str, Any] = ...) -> int: ...
Expand All @@ -33,9 +33,9 @@ if sys.version_info >= (3, 8):
@property
def exc_type(self) -> Type[BaseException]: ...
@property
def exc_value(self) -> Optional[BaseException]: ...
def exc_value(self) -> BaseException | None: ...
@property
def exc_traceback(self) -> Optional[TracebackType]: ...
def exc_traceback(self) -> TracebackType | None: ...
@property
def thread(self) -> Optional[Thread]: ...
def thread(self) -> Thread | None: ...
_excepthook: Callable[[_ExceptHookArgs], Any]
114 changes: 46 additions & 68 deletions stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ FIRST_COMPLETED: str
ALL_COMPLETED: str

if sys.version_info >= (3, 10):
def as_completed(fs: Iterable[_FutureT[_T]], *, timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ...
def as_completed(fs: Iterable[_FutureT[_T]], *, timeout: float | None = ...) -> Iterator[Future[_T]]: ...

else:
def as_completed(
fs: Iterable[_FutureT[_T]], *, loop: Optional[AbstractEventLoop] = ..., timeout: Optional[float] = ...
fs: Iterable[_FutureT[_T]], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ...
) -> Iterator[Future[_T]]: ...

@overload
def ensure_future(coro_or_future: _FT, *, loop: Optional[AbstractEventLoop] = ...) -> _FT: ... # type: ignore
def ensure_future(coro_or_future: _FT, *, loop: AbstractEventLoop | None = ...) -> _FT: ... # type: ignore
@overload
def ensure_future(coro_or_future: Awaitable[_T], *, loop: Optional[AbstractEventLoop] = ...) -> Task[_T]: ...
def ensure_future(coro_or_future: Awaitable[_T], *, loop: AbstractEventLoop | None = ...) -> Task[_T]: ...

# Prior to Python 3.7 'async' was an alias for 'ensure_future'.
# It became a keyword in 3.7.
Expand Down Expand Up @@ -91,19 +91,19 @@ if sys.version_info >= (3, 10):
return_exceptions: bool = ...,
) -> Future[List[Any]]: ...
@overload
def gather(coro_or_future1: _FutureT[_T1], *, return_exceptions: bool = ...) -> Future[Tuple[Union[_T1, BaseException]]]: ...
def gather(coro_or_future1: _FutureT[_T1], *, return_exceptions: bool = ...) -> Future[Tuple[_T1 | BaseException]]: ...
@overload
def gather(
coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], *, return_exceptions: bool = ...
) -> Future[Tuple[Union[_T1, BaseException], Union[_T2, BaseException]]]: ...
) -> Future[Tuple[_T1 | BaseException, _T2 | BaseException]]: ...
@overload
def gather(
coro_or_future1: _FutureT[_T1],
coro_or_future2: _FutureT[_T2],
coro_or_future3: _FutureT[_T3],
*,
return_exceptions: bool = ...,
) -> Future[Tuple[Union[_T1, BaseException], Union[_T2, BaseException], Union[_T3, BaseException]]]: ...
) -> Future[Tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException]]: ...
@overload
def gather(
coro_or_future1: _FutureT[_T1],
Expand All @@ -112,9 +112,7 @@ if sys.version_info >= (3, 10):
coro_or_future4: _FutureT[_T4],
*,
return_exceptions: bool = ...,
) -> Future[
Tuple[Union[_T1, BaseException], Union[_T2, BaseException], Union[_T3, BaseException], Union[_T4, BaseException]]
]: ...
) -> Future[Tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException]]: ...
@overload
def gather(
coro_or_future1: _FutureT[_T1],
Expand All @@ -125,26 +123,20 @@ if sys.version_info >= (3, 10):
*,
return_exceptions: bool = ...,
) -> Future[
Tuple[
Union[_T1, BaseException],
Union[_T2, BaseException],
Union[_T3, BaseException],
Union[_T4, BaseException],
Union[_T5, BaseException],
]
Tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException]
]: ...

else:
@overload
def gather(
coro_or_future1: _FutureT[_T1], *, loop: Optional[AbstractEventLoop] = ..., return_exceptions: Literal[False] = ...
coro_or_future1: _FutureT[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: Literal[False] = ...
) -> Future[Tuple[_T1]]: ...
@overload
def gather(
coro_or_future1: _FutureT[_T1],
coro_or_future2: _FutureT[_T2],
*,
loop: Optional[AbstractEventLoop] = ...,
loop: AbstractEventLoop | None = ...,
return_exceptions: Literal[False] = ...,
) -> Future[Tuple[_T1, _T2]]: ...
@overload
Expand All @@ -153,7 +145,7 @@ else:
coro_or_future2: _FutureT[_T2],
coro_or_future3: _FutureT[_T3],
*,
loop: Optional[AbstractEventLoop] = ...,
loop: AbstractEventLoop | None = ...,
return_exceptions: Literal[False] = ...,
) -> Future[Tuple[_T1, _T2, _T3]]: ...
@overload
Expand All @@ -163,7 +155,7 @@ else:
coro_or_future3: _FutureT[_T3],
coro_or_future4: _FutureT[_T4],
*,
loop: Optional[AbstractEventLoop] = ...,
loop: AbstractEventLoop | None = ...,
return_exceptions: Literal[False] = ...,
) -> Future[Tuple[_T1, _T2, _T3, _T4]]: ...
@overload
Expand All @@ -174,7 +166,7 @@ else:
coro_or_future4: _FutureT[_T4],
coro_or_future5: _FutureT[_T5],
*,
loop: Optional[AbstractEventLoop] = ...,
loop: AbstractEventLoop | None = ...,
return_exceptions: Literal[False] = ...,
) -> Future[Tuple[_T1, _T2, _T3, _T4, _T5]]: ...
@overload
Expand All @@ -186,42 +178,40 @@ else:
coro_or_future5: _FutureT[Any],
coro_or_future6: _FutureT[Any],
*coros_or_futures: _FutureT[Any],
loop: Optional[AbstractEventLoop] = ...,
loop: AbstractEventLoop | None = ...,
return_exceptions: bool = ...,
) -> Future[List[Any]]: ...
@overload
def gather(
coro_or_future1: _FutureT[_T1], *, loop: Optional[AbstractEventLoop] = ..., return_exceptions: bool = ...
) -> Future[Tuple[Union[_T1, BaseException]]]: ...
coro_or_future1: _FutureT[_T1], *, loop: AbstractEventLoop | None = ..., return_exceptions: bool = ...
) -> Future[Tuple[_T1 | BaseException]]: ...
@overload
def gather(
coro_or_future1: _FutureT[_T1],
coro_or_future2: _FutureT[_T2],
*,
loop: Optional[AbstractEventLoop] = ...,
loop: AbstractEventLoop | None = ...,
return_exceptions: bool = ...,
) -> Future[Tuple[Union[_T1, BaseException], Union[_T2, BaseException]]]: ...
) -> Future[Tuple[_T1 | BaseException, _T2 | BaseException]]: ...
@overload
def gather(
coro_or_future1: _FutureT[_T1],
coro_or_future2: _FutureT[_T2],
coro_or_future3: _FutureT[_T3],
*,
loop: Optional[AbstractEventLoop] = ...,
loop: AbstractEventLoop | None = ...,
return_exceptions: bool = ...,
) -> Future[Tuple[Union[_T1, BaseException], Union[_T2, BaseException], Union[_T3, BaseException]]]: ...
) -> Future[Tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException]]: ...
@overload
def gather(
coro_or_future1: _FutureT[_T1],
coro_or_future2: _FutureT[_T2],
coro_or_future3: _FutureT[_T3],
coro_or_future4: _FutureT[_T4],
*,
loop: Optional[AbstractEventLoop] = ...,
loop: AbstractEventLoop | None = ...,
return_exceptions: bool = ...,
) -> Future[
Tuple[Union[_T1, BaseException], Union[_T2, BaseException], Union[_T3, BaseException], Union[_T4, BaseException]]
]: ...
) -> Future[Tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException]]: ...
@overload
def gather(
coro_or_future1: _FutureT[_T1],
Expand All @@ -230,16 +220,10 @@ else:
coro_or_future4: _FutureT[_T4],
coro_or_future5: _FutureT[_T5],
*,
loop: Optional[AbstractEventLoop] = ...,
loop: AbstractEventLoop | None = ...,
return_exceptions: bool = ...,
) -> Future[
Tuple[
Union[_T1, BaseException],
Union[_T2, BaseException],
Union[_T3, BaseException],
Union[_T4, BaseException],
Union[_T5, BaseException],
]
Tuple[_T1 | BaseException, _T2 | BaseException, _T3 | BaseException, _T4 | BaseException, _T5 | BaseException]
]: ...

def run_coroutine_threadsafe(coro: _FutureT[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...
Expand All @@ -248,68 +232,62 @@ if sys.version_info >= (3, 10):
def shield(arg: _FutureT[_T]) -> Future[_T]: ...
def sleep(delay: float, result: _T = ...) -> Future[_T]: ...
@overload
def wait(fs: Iterable[_FT], *, timeout: Optional[float] = ..., return_when: str = ...) -> Future[Tuple[Set[_FT], Set[_FT]]]: ... # type: ignore
def wait(fs: Iterable[_FT], *, timeout: float | None = ..., return_when: str = ...) -> Future[Tuple[Set[_FT], Set[_FT]]]: ... # type: ignore
@overload
def wait(
fs: Iterable[Awaitable[_T]], *, timeout: Optional[float] = ..., return_when: str = ...
fs: Iterable[Awaitable[_T]], *, timeout: float | None = ..., return_when: str = ...
) -> Future[Tuple[Set[Task[_T]], Set[Task[_T]]]]: ...
def wait_for(fut: _FutureT[_T], timeout: Optional[float]) -> Future[_T]: ...
def wait_for(fut: _FutureT[_T], timeout: float | None) -> Future[_T]: ...

else:
def shield(arg: _FutureT[_T], *, loop: Optional[AbstractEventLoop] = ...) -> Future[_T]: ...
def sleep(delay: float, result: _T = ..., *, loop: Optional[AbstractEventLoop] = ...) -> Future[_T]: ...
def shield(arg: _FutureT[_T], *, loop: AbstractEventLoop | None = ...) -> Future[_T]: ...
def sleep(delay: float, result: _T = ..., *, loop: AbstractEventLoop | None = ...) -> Future[_T]: ...
@overload
def wait(fs: Iterable[_FT], *, loop: Optional[AbstractEventLoop] = ..., timeout: Optional[float] = ..., return_when: str = ...) -> Future[Tuple[Set[_FT], Set[_FT]]]: ... # type: ignore
def wait(fs: Iterable[_FT], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ..., return_when: str = ...) -> Future[Tuple[Set[_FT], Set[_FT]]]: ... # type: ignore
@overload
def wait(
fs: Iterable[Awaitable[_T]],
*,
loop: Optional[AbstractEventLoop] = ...,
timeout: Optional[float] = ...,
return_when: str = ...,
fs: Iterable[Awaitable[_T]], *, loop: AbstractEventLoop | None = ..., timeout: float | None = ..., return_when: str = ...
) -> Future[Tuple[Set[Task[_T]], Set[Task[_T]]]]: ...
def wait_for(fut: _FutureT[_T], timeout: Optional[float], *, loop: Optional[AbstractEventLoop] = ...) -> Future[_T]: ...
def wait_for(fut: _FutureT[_T], timeout: float | None, *, loop: AbstractEventLoop | None = ...) -> Future[_T]: ...

class Task(Future[_T], Generic[_T]):
if sys.version_info >= (3, 8):
def __init__(
self,
coro: Union[Generator[_TaskYieldType, None, _T], Awaitable[_T]],
coro: Generator[_TaskYieldType, None, _T] | Awaitable[_T],
*,
loop: AbstractEventLoop = ...,
name: Optional[str] = ...,
name: str | None = ...,
) -> None: ...
else:
def __init__(
self, coro: Union[Generator[_TaskYieldType, None, _T], Awaitable[_T]], *, loop: AbstractEventLoop = ...
self, coro: Generator[_TaskYieldType, None, _T] | Awaitable[_T], *, loop: AbstractEventLoop = ...
) -> None: ...
def __repr__(self) -> str: ...
if sys.version_info >= (3, 8):
def get_coro(self) -> Union[Generator[_TaskYieldType, None, _T], Awaitable[_T]]: ...
def get_coro(self) -> Generator[_TaskYieldType, None, _T] | Awaitable[_T]: ...
def get_name(self) -> str: ...
def set_name(self, __value: object) -> None: ...
def get_stack(self, *, limit: Optional[int] = ...) -> List[FrameType]: ...
def print_stack(self, *, limit: Optional[int] = ..., file: Optional[TextIO] = ...) -> None: ...
def get_stack(self, *, limit: int | None = ...) -> List[FrameType]: ...
def print_stack(self, *, limit: int | None = ..., file: TextIO | None = ...) -> None: ...
if sys.version_info >= (3, 9):
def cancel(self, msg: Optional[str] = ...) -> bool: ...
def cancel(self, msg: str | None = ...) -> bool: ...
else:
def cancel(self) -> bool: ...
if sys.version_info < (3, 9):
@classmethod
def current_task(cls, loop: Optional[AbstractEventLoop] = ...) -> Optional[Task[Any]]: ...
def current_task(cls, loop: AbstractEventLoop | None = ...) -> Task[Any] | None: ...
@classmethod
def all_tasks(cls, loop: Optional[AbstractEventLoop] = ...) -> Set[Task[Any]]: ...
def all_tasks(cls, loop: AbstractEventLoop | None = ...) -> Set[Task[Any]]: ...
if sys.version_info < (3, 7):
def _wakeup(self, fut: Future[Any]) -> None: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...

if sys.version_info >= (3, 7):
def all_tasks(loop: Optional[AbstractEventLoop] = ...) -> Set[Task[Any]]: ...
def all_tasks(loop: AbstractEventLoop | None = ...) -> Set[Task[Any]]: ...
if sys.version_info >= (3, 8):
def create_task(
coro: Union[Generator[_TaskYieldType, None, _T], Awaitable[_T]], *, name: Optional[str] = ...
) -> Task[_T]: ...
def create_task(coro: Generator[_TaskYieldType, None, _T] | Awaitable[_T], *, name: str | None = ...) -> Task[_T]: ...
else:
def create_task(coro: Union[Generator[_TaskYieldType, None, _T], Awaitable[_T]]) -> Task[_T]: ...
def current_task(loop: Optional[AbstractEventLoop] = ...) -> Optional[Task[Any]]: ...
def create_task(coro: Generator[_TaskYieldType, None, _T] | Awaitable[_T]) -> Task[_T]: ...
def current_task(loop: AbstractEventLoop | None = ...) -> Task[Any] | None: ...
Loading