mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
Further reduce use of deprecated contextlib aliases (#6370)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import sys
|
||||
from _typeshed import ReadableBuffer
|
||||
from typing import ContextManager, Iterable, Iterator, NoReturn, Sized, overload
|
||||
from contextlib import AbstractContextManager
|
||||
from typing import Iterable, Iterator, NoReturn, Sized, overload
|
||||
|
||||
ACCESS_DEFAULT: int
|
||||
ACCESS_READ: int
|
||||
@@ -24,7 +25,7 @@ if sys.platform != "win32":
|
||||
|
||||
PAGESIZE: int
|
||||
|
||||
class mmap(ContextManager[mmap], Iterable[int], Sized):
|
||||
class mmap(AbstractContextManager[mmap], Iterable[int], Sized):
|
||||
if sys.platform == "win32":
|
||||
def __init__(self, fileno: int, length: int, tagname: str | None = ..., access: int = ..., offset: int = ...) -> None: ...
|
||||
else:
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -11,6 +11,7 @@ from _typeshed import (
|
||||
StrPath,
|
||||
)
|
||||
from builtins import OSError
|
||||
from contextlib import AbstractContextManager
|
||||
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper
|
||||
from posix import listdir as listdir, times_result
|
||||
from subprocess import Popen
|
||||
@@ -20,7 +21,6 @@ from typing import (
|
||||
AnyStr,
|
||||
BinaryIO,
|
||||
Callable,
|
||||
ContextManager,
|
||||
Generic,
|
||||
Iterable,
|
||||
Iterator,
|
||||
@@ -640,7 +640,7 @@ def renames(old: StrOrBytesPath, new: StrOrBytesPath) -> None: ...
|
||||
def replace(src: StrOrBytesPath, dst: StrOrBytesPath, *, src_dir_fd: int | None = ..., dst_dir_fd: int | None = ...) -> None: ...
|
||||
def rmdir(path: StrOrBytesPath, *, dir_fd: int | None = ...) -> None: ...
|
||||
|
||||
class _ScandirIterator(Iterator[DirEntry[AnyStr]], ContextManager[_ScandirIterator[AnyStr]]):
|
||||
class _ScandirIterator(Iterator[DirEntry[AnyStr]], AbstractContextManager[_ScandirIterator[AnyStr]]):
|
||||
def __next__(self) -> DirEntry[AnyStr]: ...
|
||||
def close(self) -> None: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user