Further reduce use of deprecated contextlib aliases (#6370)

This commit is contained in:
Alex Waygood
2021-11-23 23:25:39 +00:00
committed by GitHub
parent b459329cec
commit a9cfd23fc3
5 changed files with 18 additions and 14 deletions

View File

@@ -3,7 +3,8 @@
import queue
import sys
import threading
from typing import Any, AnyStr, Callable, ContextManager, Generic, Iterable, Mapping, Sequence, Tuple, TypeVar
from contextlib import AbstractContextManager
from typing import Any, AnyStr, Callable, Generic, Iterable, Mapping, Sequence, Tuple, TypeVar
from .connection import Connection
from .context import BaseContext
@@ -71,7 +72,7 @@ class Server:
def serve_forever(self) -> None: ...
def accept_connection(self, c: Connection, name: str) -> None: ...
class BaseManager(ContextManager[BaseManager]):
class BaseManager(AbstractContextManager[BaseManager]):
def __init__(
self, address: Any | None = ..., authkey: bytes | None = ..., serializer: str = ..., ctx: BaseContext | None = ...
) -> None: ...
@@ -97,7 +98,7 @@ class BaseManager(ContextManager[BaseManager]):
_dict = dict
_list = list
class SyncManager(BaseManager, ContextManager[SyncManager]):
class SyncManager(BaseManager, AbstractContextManager[SyncManager]):
def BoundedSemaphore(self, value: Any = ...) -> threading.BoundedSemaphore: ...
def Condition(self, lock: Any = ...) -> threading.Condition: ...
def Event(self) -> threading.Event: ...

View File

@@ -1,6 +1,7 @@
import sys
from _typeshed import Self
from typing import Any, Callable, ContextManager, Generic, Iterable, Iterator, List, Mapping, TypeVar
from contextlib import AbstractContextManager
from typing import Any, Callable, Generic, Iterable, Iterator, List, Mapping, TypeVar
if sys.version_info >= (3, 9):
from types import GenericAlias
@@ -62,7 +63,7 @@ class IMapIterator(Iterator[_T]):
class IMapUnorderedIterator(IMapIterator[_T]): ...
class Pool(ContextManager[Pool]):
class Pool(AbstractContextManager[Pool]):
def __init__(
self,
processes: int | None = ...,
@@ -107,7 +108,7 @@ class Pool(ContextManager[Pool]):
def join(self) -> None: ...
def __enter__(self: Self) -> Self: ...
class ThreadPool(Pool, ContextManager[ThreadPool]):
class ThreadPool(Pool, AbstractContextManager[ThreadPool]):
def __init__(
self, processes: int | None = ..., initializer: Callable[..., Any] | None = ..., initargs: Iterable[Any] = ...
) -> None: ...

View File

@@ -1,7 +1,8 @@
import sys
import threading
from contextlib import AbstractContextManager
from multiprocessing.context import BaseContext
from typing import Any, Callable, ContextManager, Union
from typing import Any, Callable, Union
_LockLike = Union[Lock, RLock]
@@ -13,7 +14,7 @@ class Barrier(threading.Barrier):
class BoundedSemaphore(Semaphore):
def __init__(self, value: int = ..., *, ctx: BaseContext) -> None: ...
class Condition(ContextManager[bool]):
class Condition(AbstractContextManager[bool]):
def __init__(self, lock: _LockLike | None = ..., *, ctx: BaseContext) -> None: ...
if sys.version_info >= (3, 7):
def notify(self, n: int = ...) -> None: ...
@@ -25,7 +26,7 @@ class Condition(ContextManager[bool]):
def acquire(self, block: bool = ..., timeout: float | None = ...) -> bool: ...
def release(self) -> None: ...
class Event(ContextManager[bool]):
class Event(AbstractContextManager[bool]):
def __init__(self, lock: _LockLike | None = ..., *, ctx: BaseContext) -> None: ...
def is_set(self) -> bool: ...
def set(self) -> None: ...
@@ -42,6 +43,6 @@ class Semaphore(SemLock):
def __init__(self, value: int = ..., *, ctx: BaseContext) -> None: ...
# Not part of public API
class SemLock(ContextManager[bool]):
class SemLock(AbstractContextManager[bool]):
def acquire(self, block: bool = ..., timeout: float | None = ...) -> bool: ...
def release(self) -> None: ...