mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-07-09 18:09:17 +08:00
stdlib: add __slots__ (#14611)
This commit is contained in:
@@ -73,6 +73,7 @@ class _TaskFactory(Protocol):
|
||||
def __call__(self, loop: AbstractEventLoop, factory: _CoroutineLike[_T], /) -> Future[_T]: ...
|
||||
|
||||
class Handle:
|
||||
__slots__ = ("_callback", "_args", "_cancelled", "_loop", "_source_traceback", "_repr", "__weakref__", "_context")
|
||||
_cancelled: bool
|
||||
_args: Sequence[Any]
|
||||
def __init__(
|
||||
@@ -85,6 +86,7 @@ class Handle:
|
||||
def get_context(self) -> Context: ...
|
||||
|
||||
class TimerHandle(Handle):
|
||||
__slots__ = ["_scheduled", "_when"]
|
||||
def __init__(
|
||||
self,
|
||||
when: float,
|
||||
|
||||
@@ -6,21 +6,26 @@ from typing import Any
|
||||
__all__ = ("BaseProtocol", "Protocol", "DatagramProtocol", "SubprocessProtocol", "BufferedProtocol")
|
||||
|
||||
class BaseProtocol:
|
||||
__slots__ = ()
|
||||
def connection_made(self, transport: transports.BaseTransport) -> None: ...
|
||||
def connection_lost(self, exc: Exception | None) -> None: ...
|
||||
def pause_writing(self) -> None: ...
|
||||
def resume_writing(self) -> None: ...
|
||||
|
||||
class Protocol(BaseProtocol):
|
||||
# Need annotation or mypy will complain about 'Cannot determine type of "__slots__" in base class'
|
||||
__slots__: tuple[()] = ()
|
||||
def data_received(self, data: bytes) -> None: ...
|
||||
def eof_received(self) -> bool | None: ...
|
||||
|
||||
class BufferedProtocol(BaseProtocol):
|
||||
__slots__ = ()
|
||||
def get_buffer(self, sizehint: int) -> ReadableBuffer: ...
|
||||
def buffer_updated(self, nbytes: int) -> None: ...
|
||||
def eof_received(self) -> bool | None: ...
|
||||
|
||||
class DatagramProtocol(BaseProtocol):
|
||||
__slots__ = ()
|
||||
def connection_made(self, transport: transports.DatagramTransport) -> None: ... # type: ignore[override]
|
||||
# addr can be a tuple[int, int] for some unusual protocols like socket.AF_NETLINK.
|
||||
# Use tuple[str | Any, int] to not cause typechecking issues on most usual cases.
|
||||
@@ -30,6 +35,7 @@ class DatagramProtocol(BaseProtocol):
|
||||
def error_received(self, exc: Exception) -> None: ...
|
||||
|
||||
class SubprocessProtocol(BaseProtocol):
|
||||
__slots__: tuple[()] = ()
|
||||
def pipe_data_received(self, fd: int, data: bytes) -> None: ...
|
||||
def pipe_connection_lost(self, fd: int, exc: Exception | None) -> None: ...
|
||||
def process_exited(self) -> None: ...
|
||||
|
||||
@@ -8,6 +8,7 @@ from typing import Any
|
||||
__all__ = ("BaseTransport", "ReadTransport", "WriteTransport", "Transport", "DatagramTransport", "SubprocessTransport")
|
||||
|
||||
class BaseTransport:
|
||||
__slots__ = ("_extra",)
|
||||
def __init__(self, extra: Mapping[str, Any] | None = None) -> None: ...
|
||||
def get_extra_info(self, name: str, default: Any = None) -> Any: ...
|
||||
def is_closing(self) -> bool: ...
|
||||
@@ -16,11 +17,13 @@ class BaseTransport:
|
||||
def get_protocol(self) -> BaseProtocol: ...
|
||||
|
||||
class ReadTransport(BaseTransport):
|
||||
__slots__ = ()
|
||||
def is_reading(self) -> bool: ...
|
||||
def pause_reading(self) -> None: ...
|
||||
def resume_reading(self) -> None: ...
|
||||
|
||||
class WriteTransport(BaseTransport):
|
||||
__slots__ = ()
|
||||
def set_write_buffer_limits(self, high: int | None = None, low: int | None = None) -> None: ...
|
||||
def get_write_buffer_size(self) -> int: ...
|
||||
def get_write_buffer_limits(self) -> tuple[int, int]: ...
|
||||
@@ -32,13 +35,16 @@ class WriteTransport(BaseTransport):
|
||||
def can_write_eof(self) -> bool: ...
|
||||
def abort(self) -> None: ...
|
||||
|
||||
class Transport(ReadTransport, WriteTransport): ...
|
||||
class Transport(ReadTransport, WriteTransport):
|
||||
__slots__ = ()
|
||||
|
||||
class DatagramTransport(BaseTransport):
|
||||
__slots__ = ()
|
||||
def sendto(self, data: bytes | bytearray | memoryview, addr: _Address | None = None) -> None: ...
|
||||
def abort(self) -> None: ...
|
||||
|
||||
class SubprocessTransport(BaseTransport):
|
||||
__slots__ = ()
|
||||
def get_pid(self) -> int: ...
|
||||
def get_returncode(self) -> int | None: ...
|
||||
def get_pipe_transport(self, fd: int) -> BaseTransport | None: ...
|
||||
@@ -47,4 +53,5 @@ class SubprocessTransport(BaseTransport):
|
||||
def kill(self) -> None: ...
|
||||
|
||||
class _FlowControlMixin(Transport):
|
||||
__slots__ = ("_loop", "_protocol_paused", "_high_water", "_low_water")
|
||||
def __init__(self, extra: Mapping[str, Any] | None = None, loop: AbstractEventLoop | None = None) -> None: ...
|
||||
|
||||
@@ -14,6 +14,7 @@ _WriteBuffer: TypeAlias = bytearray | memoryview
|
||||
_CMSG: TypeAlias = tuple[int, int, bytes]
|
||||
|
||||
class TransportSocket:
|
||||
__slots__ = ("_sock",)
|
||||
def __init__(self, sock: socket.socket) -> None: ...
|
||||
@property
|
||||
def family(self) -> int: ...
|
||||
|
||||
Reference in New Issue
Block a user