From 20a35057fae79e46de429b79625f1c4fd992f66d Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Tue, 22 Nov 2022 12:55:43 +0100 Subject: [PATCH] Further annotate pika (#9240) --- stubs/pika/@tests/stubtest_allowlist.txt | 4 + .../pika/pika/adapters/asyncio_connection.pyi | 28 +-- stubs/pika/pika/adapters/base_connection.pyi | 17 +- .../pika/adapters/blocking_connection.pyi | 45 ++-- stubs/pika/pika/channel.pyi | 57 +++-- stubs/pika/pika/compat.pyi | 27 ++- stubs/pika/pika/connection.pyi | 204 +++++++++--------- stubs/pika/pika/credentials.pyi | 34 +-- stubs/pika/pika/data.pyi | 20 +- stubs/pika/pika/frame.pyi | 53 ++--- 10 files changed, 268 insertions(+), 221 deletions(-) diff --git a/stubs/pika/@tests/stubtest_allowlist.txt b/stubs/pika/@tests/stubtest_allowlist.txt index bf59bfda8..62faccc9c 100644 --- a/stubs/pika/@tests/stubtest_allowlist.txt +++ b/stubs/pika/@tests/stubtest_allowlist.txt @@ -26,3 +26,7 @@ pika.data.PY2 pika.data.basestring pika.spec.str_or_bytes pika.validators.basestring + +# Arguments have a sentinel default, which is not reflected in the stubs. +pika.ConnectionParameters.__init__ +pika.connection.ConnectionParameters.__init__ diff --git a/stubs/pika/pika/adapters/asyncio_connection.pyi b/stubs/pika/pika/adapters/asyncio_connection.pyi index db55d27ea..57a3257cd 100644 --- a/stubs/pika/pika/adapters/asyncio_connection.pyi +++ b/stubs/pika/pika/adapters/asyncio_connection.pyi @@ -1,23 +1,27 @@ -from _typeshed import Incomplete +from _typeshed import Incomplete, Self +from asyncio import AbstractEventLoop +from collections.abc import Callable +from logging import Logger -from pika.adapters import base_connection -from pika.adapters.utils import io_services_utils, nbio_interface +from ..connection import Parameters +from .base_connection import BaseConnection +from .utils import io_services_utils, nbio_interface -LOGGER: Incomplete +LOGGER: Logger -class AsyncioConnection(base_connection.BaseConnection): +class AsyncioConnection(BaseConnection): def __init__( - self, - parameters: Incomplete | None = ..., - on_open_callback: Incomplete | None = ..., - on_open_error_callback: Incomplete | None = ..., - on_close_callback: Incomplete | None = ..., - custom_ioloop: Incomplete | None = ..., + self: Self, + parameters: Parameters | None = ..., + on_open_callback: Callable[[Self], object] | None = ..., + on_open_error_callback: Callable[[Self, BaseException], object] | None = ..., + on_close_callback: Callable[[Self, BaseException], object] | None = ..., + custom_ioloop: AbstractEventLoop | None = ..., internal_connection_workflow: bool = ..., ) -> None: ... @classmethod def create_connection( - cls, connection_configs, on_done, custom_ioloop: Incomplete | None = ..., workflow: Incomplete | None = ... + cls, connection_configs, on_done, custom_ioloop: AbstractEventLoop | None = ..., workflow: Incomplete | None = ... ): ... class _AsyncioIOServicesAdapter( diff --git a/stubs/pika/pika/adapters/base_connection.pyi b/stubs/pika/pika/adapters/base_connection.pyi index ba21c0118..3cf7ed97f 100644 --- a/stubs/pika/pika/adapters/base_connection.pyi +++ b/stubs/pika/pika/adapters/base_connection.pyi @@ -1,14 +1,21 @@ import abc -from _typeshed import Incomplete +from _typeshed import Incomplete, Self +from collections.abc import Callable -from pika import connection -from pika.adapters.utils import nbio_interface +from ..adapters.utils import nbio_interface +from ..connection import Connection LOGGER: Incomplete -class BaseConnection(connection.Connection, metaclass=abc.ABCMeta): +class BaseConnection(Connection, metaclass=abc.ABCMeta): def __init__( - self, parameters, on_open_callback, on_open_error_callback, on_close_callback, nbio, internal_connection_workflow + self: Self, + parameters, + on_open_callback: Callable[[Self], object] | None, + on_open_error_callback: Callable[[Self, BaseException], object] | None, + on_close_callback: Callable[[Self, BaseException], object] | None, + nbio, + internal_connection_workflow: bool, ) -> None: ... @classmethod @abc.abstractmethod diff --git a/stubs/pika/pika/adapters/blocking_connection.pyi b/stubs/pika/pika/adapters/blocking_connection.pyi index 6093ca3d4..c0907f2f3 100644 --- a/stubs/pika/pika/adapters/blocking_connection.pyi +++ b/stubs/pika/pika/adapters/blocking_connection.pyi @@ -1,7 +1,12 @@ -from _typeshed import Incomplete -from collections.abc import Generator +from _typeshed import Incomplete, Self +from collections.abc import Generator, Sequence from typing import NamedTuple +from ..connection import Parameters +from ..data import _ArgumentMapping +from ..exchange_type import ExchangeType +from ..spec import BasicProperties + LOGGER: Incomplete class _CallbackResult: @@ -47,9 +52,11 @@ class BlockingConnection: class _OnChannelOpenedArgs(NamedTuple): channel: Incomplete - def __init__(self, parameters: Incomplete | None = ..., _impl_class: Incomplete | None = ...) -> None: ... - def __enter__(self): ... - def __exit__(self, exc_type, value, traceback) -> None: ... + def __init__( + self, parameters: Parameters | Sequence[Parameters] | None = ..., _impl_class: Incomplete | None = ... + ) -> None: ... + def __enter__(self: Self) -> Self: ... + def __exit__(self, exc_type: object, value: object, traceback: object) -> None: ... def add_on_connection_blocked_callback(self, callback) -> None: ... def add_on_connection_unblocked_callback(self, callback) -> None: ... def call_later(self, delay, callback): ... @@ -58,20 +65,20 @@ class BlockingConnection: def update_secret(self, new_secret, reason) -> None: ... def close(self, reply_code: int = ..., reply_text: str = ...) -> None: ... def process_data_events(self, time_limit: int = ...): ... - def sleep(self, duration) -> None: ... - def channel(self, channel_number: Incomplete | None = ...): ... + def sleep(self, duration: float) -> None: ... + def channel(self, channel_number: int | None = ...) -> BlockingChannel: ... @property - def is_closed(self): ... + def is_closed(self) -> bool: ... @property - def is_open(self): ... + def is_open(self) -> bool: ... @property - def basic_nack_supported(self): ... + def basic_nack_supported(self) -> bool: ... @property - def consumer_cancel_notify_supported(self): ... + def consumer_cancel_notify_supported(self) -> bool: ... @property - def exchange_exchange_bindings_supported(self): ... + def exchange_exchange_bindings_supported(self) -> bool: ... @property - def publisher_confirms_supported(self): ... + def publisher_confirms_supported(self) -> bool: ... basic_nack = basic_nack_supported consumer_cancel_notify = consumer_cancel_notify_supported exchange_exchange_bindings = exchange_exchange_bindings_supported @@ -192,22 +199,24 @@ class BlockingChannel: def basic_ack(self, delivery_tag: int = ..., multiple: bool = ...) -> None: ... def basic_nack(self, delivery_tag: int = ..., multiple: bool = ..., requeue: bool = ...) -> None: ... def basic_get(self, queue, auto_ack: bool = ...): ... - def basic_publish(self, exchange, routing_key, body, properties: Incomplete | None = ..., mandatory: bool = ...) -> None: ... + def basic_publish( + self, exchange: str, routing_key: str, body: str | bytes, properties: BasicProperties | None = ..., mandatory: bool = ... + ) -> None: ... def basic_qos(self, prefetch_size: int = ..., prefetch_count: int = ..., global_qos: bool = ...) -> None: ... def basic_recover(self, requeue: bool = ...) -> None: ... def basic_reject(self, delivery_tag: int = ..., requeue: bool = ...) -> None: ... def confirm_delivery(self) -> None: ... def exchange_declare( self, - exchange, - exchange_type=..., + exchange: str, + exchange_type: ExchangeType | str = ..., passive: bool = ..., durable: bool = ..., auto_delete: bool = ..., internal: bool = ..., - arguments: Incomplete | None = ..., + arguments: _ArgumentMapping | None = ..., ): ... - def exchange_delete(self, exchange: Incomplete | None = ..., if_unused: bool = ...): ... + def exchange_delete(self, exchange: str | None = ..., if_unused: bool = ...): ... def exchange_bind(self, destination, source, routing_key: str = ..., arguments: Incomplete | None = ...): ... def exchange_unbind( self, diff --git a/stubs/pika/pika/channel.pyi b/stubs/pika/pika/channel.pyi index b2556b821..424001278 100644 --- a/stubs/pika/pika/channel.pyi +++ b/stubs/pika/pika/channel.pyi @@ -1,18 +1,27 @@ -from _typeshed import Incomplete +from _typeshed import Incomplete, Self +from collections.abc import Callable +from typing_extensions import Final + +from .callback import CallbackManager +from .connection import Connection +from .data import _ArgumentMapping +from .exchange_type import ExchangeType +from .frame import Method +from .spec import Basic, BasicProperties LOGGER: Incomplete MAX_CHANNELS: int class Channel: - CLOSED: int - OPENING: int - OPEN: int - CLOSING: int - channel_number: Incomplete - callbacks: Incomplete - connection: Incomplete + CLOSED: Final[int] + OPENING: Final[int] + OPEN: Final[int] + CLOSING: Final[int] + channel_number: int + callbacks: CallbackManager + connection: Connection flow_active: bool - def __init__(self, connection, channel_number, on_open_callback) -> None: ... + def __init__(self: Self, connection: Connection, channel_number: int, on_open_callback: Callable[[Self], object]) -> None: ... def __int__(self) -> int: ... def add_callback(self, callback, replies, one_shot: bool = ...) -> None: ... def add_on_cancel_callback(self, callback) -> None: ... @@ -20,20 +29,22 @@ class Channel: def add_on_flow_callback(self, callback) -> None: ... def add_on_return_callback(self, callback) -> None: ... def basic_ack(self, delivery_tag: int = ..., multiple: bool = ...): ... - def basic_cancel(self, consumer_tag: str = ..., callback: Incomplete | None = ...) -> None: ... + def basic_cancel(self, consumer_tag: str = ..., callback: Callable[[Method], object] | None = ...) -> None: ... def basic_consume( self, - queue, - on_message_callback, + queue: str, + on_message_callback: Callable[[Channel, Basic.Deliver, BasicProperties, bytes], object], auto_ack: bool = ..., exclusive: bool = ..., - consumer_tag: Incomplete | None = ..., - arguments: Incomplete | None = ..., - callback: Incomplete | None = ..., - ): ... + consumer_tag: str | None = ..., + arguments: _ArgumentMapping | None = ..., + callback: Callable[[Method], object] | None = ..., + ) -> str: ... def basic_get(self, queue, callback, auto_ack: bool = ...) -> None: ... def basic_nack(self, delivery_tag: int = ..., multiple: bool = ..., requeue: bool = ...): ... - def basic_publish(self, exchange, routing_key, body, properties: Incomplete | None = ..., mandatory: bool = ...) -> None: ... + def basic_publish( + self, exchange: str, routing_key: str, body: str | bytes, properties: BasicProperties | None = ..., mandatory: bool = ... + ) -> None: ... def basic_qos( self, prefetch_size: int = ..., prefetch_count: int = ..., global_qos: bool = ..., callback: Incomplete | None = ... ): ... @@ -48,16 +59,18 @@ class Channel: ): ... def exchange_declare( self, - exchange, - exchange_type=..., + exchange: str, + exchange_type: ExchangeType | str = ..., passive: bool = ..., durable: bool = ..., auto_delete: bool = ..., internal: bool = ..., - arguments: Incomplete | None = ..., - callback: Incomplete | None = ..., + arguments: _ArgumentMapping | None = ..., + callback: Callable[[Method], object] | None = ..., + ): ... + def exchange_delete( + self, exchange: str | None = ..., if_unused: bool = ..., callback: Callable[[Method], object] | None = ... ): ... - def exchange_delete(self, exchange: Incomplete | None = ..., if_unused: bool = ..., callback: Incomplete | None = ...): ... def exchange_unbind( self, destination: Incomplete | None = ..., diff --git a/stubs/pika/pika/compat.pyi b/stubs/pika/pika/compat.pyi index 6bb418408..de6dd8e9d 100644 --- a/stubs/pika/pika/compat.pyi +++ b/stubs/pika/pika/compat.pyi @@ -1,9 +1,14 @@ from abc import ABCMeta +from collections.abc import ItemsView, Mapping, ValuesView from io import StringIO as StringIO from re import Pattern -from typing_extensions import Final, Literal +from typing import Any, TypeVar +from typing_extensions import Final, Literal, SupportsIndex, TypeGuard from urllib.parse import parse_qs, quote, unquote, urlencode as urlencode, urlparse as urlparse +_KT = TypeVar("_KT") +_VT_co = TypeVar("_VT_co", covariant=True) + url_quote = quote url_unquote = unquote url_parse_qs = parse_qs @@ -24,19 +29,19 @@ str_or_bytes: Final[tuple[type[str], type[bytes]]] xrange = range unicode_type = str -def time_now(): ... -def dictkeys(dct): ... -def dictvalues(dct): ... -def dict_iteritems(dct): ... -def dict_itervalues(dct): ... -def byte(*args): ... +def time_now() -> float: ... +def dictkeys(dct: Mapping[_KT, Any]) -> list[_KT]: ... +def dictvalues(dct: Mapping[Any, _VT_co]) -> list[_VT_co]: ... +def dict_iteritems(dct: Mapping[_KT, _VT_co]) -> ItemsView[_KT, _VT_co]: ... +def dict_itervalues(dct: Mapping[Any, _VT_co]) -> ValuesView[_VT_co]: ... +def byte(*args: SupportsIndex) -> bytes: ... class long(int): ... -def canonical_str(value): ... -def is_integer(value): ... -def as_bytes(value): ... -def to_digit(value): ... +def canonical_str(value: object) -> str: ... +def is_integer(value: object) -> TypeGuard[int]: ... +def as_bytes(value: str | bytes) -> bytes: ... +def to_digit(value: str) -> int: ... def get_linux_version(release_str: str) -> tuple[int, int, int]: ... HAVE_SIGNAL: Final[bool] diff --git a/stubs/pika/pika/connection.pyi b/stubs/pika/pika/connection.pyi index 79490cbeb..aa7dde5e3 100644 --- a/stubs/pika/pika/connection.pyi +++ b/stubs/pika/pika/connection.pyi @@ -1,10 +1,17 @@ import abc -from _typeshed import Incomplete +from _typeshed import Incomplete, Self +from collections.abc import Callable +from logging import Logger +from typing_extensions import Final -from pika.compat import AbstractBase +from .callback import CallbackManager +from .channel import Channel +from .compat import AbstractBase +from .credentials import _Credentials +from .frame import Method PRODUCT: str -LOGGER: Incomplete +LOGGER: Logger class Parameters: DEFAULT_USERNAME: str @@ -28,119 +35,96 @@ class Parameters: DEFAULT_VIRTUAL_HOST: str DEFAULT_TCP_OPTIONS: Incomplete def __init__(self) -> None: ... - def __eq__(self, other): ... - def __ne__(self, other): ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... @property - def blocked_connection_timeout(self): ... + def blocked_connection_timeout(self) -> float | None: ... @blocked_connection_timeout.setter - def blocked_connection_timeout(self, value) -> None: ... + def blocked_connection_timeout(self, value: float | None) -> None: ... @property - def channel_max(self): ... + def channel_max(self) -> int: ... @channel_max.setter - def channel_max(self, value) -> None: ... + def channel_max(self, value: int) -> None: ... @property - def client_properties(self): ... + def client_properties(self) -> dict[Incomplete, Incomplete] | None: ... @client_properties.setter - def client_properties(self, value) -> None: ... + def client_properties(self, value: dict[Incomplete, Incomplete] | None) -> None: ... @property - def connection_attempts(self): ... + def connection_attempts(self) -> int: ... @connection_attempts.setter - def connection_attempts(self, value) -> None: ... + def connection_attempts(self, value: int) -> None: ... @property - def credentials(self): ... + def credentials(self) -> _Credentials: ... @credentials.setter - def credentials(self, value) -> None: ... + def credentials(self, value: _Credentials) -> None: ... @property - def frame_max(self): ... + def frame_max(self) -> int: ... @frame_max.setter - def frame_max(self, value) -> None: ... + def frame_max(self, value: int) -> None: ... @property - def heartbeat(self): ... + def heartbeat(self) -> int | Callable[[Connection, int], int] | None: ... @heartbeat.setter - def heartbeat(self, value) -> None: ... + def heartbeat(self, value: int | Callable[[Connection, int], int] | None) -> None: ... @property - def host(self): ... + def host(self) -> str: ... @host.setter - def host(self, value) -> None: ... + def host(self, value: str) -> None: ... @property - def locale(self): ... + def locale(self) -> str: ... @locale.setter - def locale(self, value) -> None: ... + def locale(self, value: str) -> None: ... @property - def port(self): ... + def port(self) -> int: ... @port.setter - def port(self, value) -> None: ... + def port(self, value: int | str) -> None: ... @property - def retry_delay(self): ... + def retry_delay(self) -> int | float: ... @retry_delay.setter - def retry_delay(self, value) -> None: ... + def retry_delay(self, value: float) -> None: ... @property - def socket_timeout(self): ... + def socket_timeout(self) -> float | None: ... @socket_timeout.setter - def socket_timeout(self, value) -> None: ... + def socket_timeout(self, value: float | None) -> None: ... @property - def stack_timeout(self): ... + def stack_timeout(self) -> float | None: ... @stack_timeout.setter - def stack_timeout(self, value) -> None: ... + def stack_timeout(self, value: float | None) -> None: ... @property - def ssl_options(self): ... + def ssl_options(self) -> SSLOptions | None: ... @ssl_options.setter - def ssl_options(self, value) -> None: ... + def ssl_options(self, value: SSLOptions | None) -> None: ... @property - def virtual_host(self): ... + def virtual_host(self) -> str: ... @virtual_host.setter - def virtual_host(self, value) -> None: ... + def virtual_host(self, value: str) -> None: ... @property - def tcp_options(self): ... + def tcp_options(self) -> dict[Incomplete, Incomplete] | None: ... @tcp_options.setter - def tcp_options(self, value) -> None: ... + def tcp_options(self, value: dict[Incomplete, Incomplete] | None) -> None: ... class ConnectionParameters(Parameters): - class _DEFAULT: ... - blocked_connection_timeout: Incomplete - channel_max: Incomplete - client_properties: Incomplete - connection_attempts: Incomplete - credentials: Incomplete - frame_max: Incomplete - heartbeat: Incomplete - host: Incomplete - locale: Incomplete - retry_delay: Incomplete - socket_timeout: Incomplete - stack_timeout: Incomplete - ssl_options: Incomplete - port: Incomplete - virtual_host: Incomplete - tcp_options: Incomplete def __init__( self, - host=..., - port=..., - virtual_host=..., - credentials=..., - channel_max=..., - frame_max=..., - heartbeat=..., - ssl_options=..., - connection_attempts=..., - retry_delay=..., - socket_timeout=..., - stack_timeout=..., - locale=..., - blocked_connection_timeout=..., - client_properties=..., - tcp_options=..., - **kwargs, + host: str = ..., + port: int | str = ..., + virtual_host: str = ..., + credentials: _Credentials = ..., + channel_max: int = ..., + frame_max: int = ..., + heartbeat: int | Callable[[Connection, int], int] | None = ..., + ssl_options: SSLOptions | None = ..., + connection_attempts: int = ..., + retry_delay: float = ..., + socket_timeout: float | None = ..., + stack_timeout: float | None = ..., + locale: str = ..., + blocked_connection_timeout: float | None = ..., + client_properties: dict[Incomplete, Incomplete] | None = ..., + tcp_options: dict[Incomplete, Incomplete] | None = ..., ) -> None: ... class URLParameters(Parameters): - ssl_options: Incomplete - host: Incomplete - port: Incomplete - credentials: Incomplete - virtual_host: Incomplete - def __init__(self, url) -> None: ... + def __init__(self, url: str) -> None: ... class SSLOptions: context: Incomplete @@ -148,49 +132,53 @@ class SSLOptions: def __init__(self, context, server_hostname: Incomplete | None = ...) -> None: ... class Connection(AbstractBase, metaclass=abc.ABCMeta): - ON_CONNECTION_CLOSED: str - ON_CONNECTION_ERROR: str - ON_CONNECTION_OPEN_OK: str - CONNECTION_CLOSED: int - CONNECTION_INIT: int - CONNECTION_PROTOCOL: int - CONNECTION_START: int - CONNECTION_TUNE: int - CONNECTION_OPEN: int - CONNECTION_CLOSING: int - connection_state: Incomplete - params: Incomplete - callbacks: Incomplete + ON_CONNECTION_CLOSED: Final[str] + ON_CONNECTION_ERROR: Final[str] + ON_CONNECTION_OPEN_OK: Final[str] + CONNECTION_CLOSED: Final[int] + CONNECTION_INIT: Final[int] + CONNECTION_PROTOCOL: Final[int] + CONNECTION_START: Final[int] + CONNECTION_TUNE: Final[int] + CONNECTION_OPEN: Final[int] + CONNECTION_CLOSING: Final[int] + connection_state: int # one of the constants above + params: Parameters + callbacks: CallbackManager server_capabilities: Incomplete server_properties: Incomplete known_hosts: Incomplete def __init__( - self, - parameters: Incomplete | None = ..., - on_open_callback: Incomplete | None = ..., - on_open_error_callback: Incomplete | None = ..., - on_close_callback: Incomplete | None = ..., + self: Self, + parameters: Parameters | None = ..., + on_open_callback: Callable[[Self], object] | None = ..., + on_open_error_callback: Callable[[Self, BaseException], object] | None = ..., + on_close_callback: Callable[[Self, BaseException], object] | None = ..., internal_connection_workflow: bool = ..., ) -> None: ... - def add_on_close_callback(self, callback) -> None: ... - def add_on_connection_blocked_callback(self, callback) -> None: ... - def add_on_connection_unblocked_callback(self, callback) -> None: ... - def add_on_open_callback(self, callback) -> None: ... - def add_on_open_error_callback(self, callback, remove_default: bool = ...) -> None: ... - def channel(self, channel_number: Incomplete | None = ..., on_open_callback: Incomplete | None = ...): ... + def add_on_close_callback(self: Self, callback: Callable[[Self, BaseException], object]) -> None: ... + def add_on_connection_blocked_callback(self: Self, callback: Callable[[Self, Method], object]) -> None: ... + def add_on_connection_unblocked_callback(self: Self, callback: Callable[[Self, Method], object]) -> None: ... + def add_on_open_callback(self: Self, callback: Callable[[Self], object]) -> None: ... + def add_on_open_error_callback( + self: Self, callback: Callable[[Self, BaseException], object], remove_default: bool = ... + ) -> None: ... + def channel( + self, channel_number: int | None = ..., on_open_callback: Callable[[Channel], object] | None = ... + ) -> Channel: ... def update_secret(self, new_secret, reason, callback: Incomplete | None = ...) -> None: ... def close(self, reply_code: int = ..., reply_text: str = ...) -> None: ... @property - def is_closed(self): ... + def is_closed(self) -> bool: ... @property - def is_closing(self): ... + def is_closing(self) -> bool: ... @property - def is_open(self): ... + def is_open(self) -> bool: ... @property - def basic_nack(self): ... + def basic_nack(self) -> bool: ... @property - def consumer_cancel_notify(self): ... + def consumer_cancel_notify(self) -> bool: ... @property - def exchange_exchange_bindings(self): ... + def exchange_exchange_bindings(self) -> bool: ... @property - def publisher_confirms(self): ... + def publisher_confirms(self) -> bool: ... diff --git a/stubs/pika/pika/credentials.pyi b/stubs/pika/pika/credentials.pyi index 4f4a37117..b813f7c99 100644 --- a/stubs/pika/pika/credentials.pyi +++ b/stubs/pika/pika/credentials.pyi @@ -1,25 +1,33 @@ from _typeshed import Incomplete +from logging import Logger +from typing import ClassVar +from typing_extensions import TypeAlias -LOGGER: Incomplete +from .spec import Connection + +# TODO: This could be turned into a protocol. +_Credentials: TypeAlias = Incomplete # noqa: Y047 + +LOGGER: Logger class PlainCredentials: - TYPE: str - username: Incomplete - password: Incomplete - erase_on_connect: Incomplete - def __init__(self, username, password, erase_on_connect: bool = ...) -> None: ... - def __eq__(self, other): ... - def __ne__(self, other): ... - def response_for(self, start): ... + TYPE: ClassVar[str] + username: str + password: str + erase_on_connect: bool + def __init__(self, username: str, password: str, erase_on_connect: bool = ...) -> None: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def response_for(self, start: Connection.Start) -> tuple[str | None, bytes | None]: ... def erase_credentials(self) -> None: ... class ExternalCredentials: - TYPE: str + TYPE: ClassVar[str] erase_on_connect: bool def __init__(self) -> None: ... - def __eq__(self, other): ... - def __ne__(self, other): ... - def response_for(self, start): ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def response_for(self, start: Connection.Start) -> tuple[str | None, bytes | None]: ... def erase_credentials(self) -> None: ... VALID_TYPES: Incomplete diff --git a/stubs/pika/pika/data.pyi b/stubs/pika/pika/data.pyi index 3f35fb4d1..c32cde389 100644 --- a/stubs/pika/pika/data.pyi +++ b/stubs/pika/pika/data.pyi @@ -1,6 +1,14 @@ -def encode_short_string(pieces, value): ... -def decode_short_string(encoded, offset): ... -def encode_table(pieces, table): ... -def encode_value(pieces, value): ... -def decode_table(encoded, offset): ... -def decode_value(encoded, offset): ... +from collections.abc import Mapping +from datetime import datetime +from decimal import Decimal +from typing_extensions import TypeAlias + +_Value: TypeAlias = str | bytes | bool | int | Decimal | datetime | _ArgumentMapping | list[_Value] | None +_ArgumentMapping: TypeAlias = Mapping[str, _Value] + +def encode_short_string(pieces: list[bytes], value: str | bytes) -> int: ... +def decode_short_string(encoded: bytes, offset: int) -> tuple[str, int]: ... +def encode_table(pieces: list[bytes], table: _ArgumentMapping) -> int: ... +def encode_value(pieces: list[bytes], value: _Value) -> int: ... +def decode_table(encoded: bytes, offset: int) -> tuple[dict[str, _Value], int]: ... +def decode_value(encoded: bytes, offset: int) -> tuple[_Value, int]: ... diff --git a/stubs/pika/pika/frame.pyi b/stubs/pika/pika/frame.pyi index 632f04b24..c68959506 100644 --- a/stubs/pika/pika/frame.pyi +++ b/stubs/pika/pika/frame.pyi @@ -1,43 +1,44 @@ -from _typeshed import Incomplete +from abc import abstractmethod +from logging import Logger -from pika.amqp_object import AMQPObject +from .amqp_object import AMQPObject, Method as AMQPMethod +from .spec import BasicProperties -LOGGER: Incomplete +LOGGER: Logger class Frame(AMQPObject): - frame_type: Incomplete - channel_number: Incomplete - def __init__(self, frame_type, channel_number) -> None: ... - def marshal(self) -> None: ... + frame_type: int + channel_number: int + def __init__(self, frame_type: int, channel_number: int) -> None: ... + @abstractmethod + def marshal(self) -> bytes: ... class Method(Frame): - method: Incomplete - def __init__(self, channel_number, method) -> None: ... - def marshal(self): ... + method: AMQPMethod + def __init__(self, channel_number: int, method: AMQPMethod) -> None: ... + def marshal(self) -> bytes: ... class Header(Frame): - body_size: Incomplete - properties: Incomplete - def __init__(self, channel_number, body_size, props) -> None: ... - def marshal(self): ... + body_size: int + properties: BasicProperties + def __init__(self, channel_number: int, body_size: int, props: BasicProperties) -> None: ... + def marshal(self) -> bytes: ... class Body(Frame): - fragment: Incomplete - def __init__(self, channel_number, fragment) -> None: ... - def marshal(self): ... + fragment: bytes + def __init__(self, channel_number: int, fragment: bytes) -> None: ... + def marshal(self) -> bytes: ... class Heartbeat(Frame): def __init__(self) -> None: ... - def marshal(self): ... + def marshal(self) -> bytes: ... class ProtocolHeader(AMQPObject): frame_type: int - major: Incomplete - minor: Incomplete - revision: Incomplete - def __init__( - self, major: Incomplete | None = ..., minor: Incomplete | None = ..., revision: Incomplete | None = ... - ) -> None: ... - def marshal(self): ... + major: int + minor: int + revision: int + def __init__(self, major: int | None = ..., minor: int | None = ..., revision: int | None = ...) -> None: ... + def marshal(self) -> bytes: ... -def decode_frame(data_in): ... +def decode_frame(data_in: bytes) -> tuple[int, Frame | None]: ...