Skip to content
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
5 changes: 4 additions & 1 deletion pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@
"stubs/parsimonious/parsimonious/nodes.pyi",
"stubs/peewee",
"stubs/pexpect",
"stubs/pika",
"stubs/pika/pika/adapters/twisted_connection.pyi",
"stubs/pika/pika/adapters/utils/connection_workflow.pyi",
"stubs/pika/pika/callback.pyi",
"stubs/pika/pika/channel.pyi",
"stubs/pony",
"stubs/protobuf",
"stubs/psutil/psutil/__init__.pyi",
Expand Down
3 changes: 3 additions & 0 deletions stubs/pika/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# bytes alias for Python 3 compatibility
pika.spec.str

# Behind a TYPE_CHECKING guard at runtime.
pika.adapters.select_connection.SELECT_ERROR_T
pika.adapters.select_connection.POLLER_PARAMS
Expand Down
6 changes: 3 additions & 3 deletions stubs/pika/pika/adapters/base_connection.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc
from _typeshed import Incomplete
from collections.abc import Callable, Mapping, Sequence
from collections.abc import Callable, Sequence
from logging import Logger
from typing import Final, Generic, Literal, TypeVar
from typing_extensions import Self
Expand Down Expand Up @@ -62,8 +62,8 @@ class _StreamingProtocolShim(AbstractStreamProtocol, Generic[_IOLoop]):
connection_state: Literal[0, 1, 2, 3, 4, 5, 6] # one of the constants above
params: Parameters
callbacks: CallbackManager
server_capabilities: Mapping[str, bool] | None
server_properties: Mapping[str, Incomplete] | None
server_capabilities: dict[str, bool] | None
server_properties: dict[str, Incomplete] | None
known_hosts: str | None
def add_on_close_callback(self, callback: Callable[[Self, BaseException], object]) -> None: ...
def add_on_connection_blocked_callback(self, callback: Callable[[Self, Method[SpecConnection.Blocked]], object]) -> None: ...
Expand Down
2 changes: 1 addition & 1 deletion stubs/pika/pika/adapters/twisted_connection.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class _TwistedConnectionAdapter(Connection):
self,
parameters: Parameters | None,
on_open_callback: Callable[[Connection], object] | None,
on_open_error_callback: Callable[[Connection, Exception], object] | None,
on_open_error_callback: Callable[[Connection, BaseException], object] | None,
on_close_callback: Callable[[Connection, Exception], object] | None,
custom_reactor: ReactorBase | None = None,
) -> None: ...
Expand Down
46 changes: 30 additions & 16 deletions stubs/pika/pika/callback.pyi
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
from collections.abc import Callable
from _typeshed import Incomplete
from collections.abc import Callable, Mapping
from logging import Logger
from typing import Literal, TypeAlias
from typing import Any, Final, Literal, ParamSpec, TypeAlias, TypeVar

from .amqp_object import AMQPObject

_P = ParamSpec("_P")
_R = TypeVar("_R")
AMQPValue: TypeAlias = type[AMQPObject] | AMQPObject | int | str

LOGGER: Logger

def name_or_value(value: AMQPValue) -> str: ...
def sanitize_prefix(function): ...
def check_for_prefix_and_key(function): ...
def sanitize_prefix(function: Callable[_P, _R]) -> Callable[_P, _R]: ...
def check_for_prefix_and_key(function: Callable[_P, _R]) -> Callable[_P, _R | Literal[False]]: ...

class CallbackManager:
CALLS: str
ARGUMENTS: str
DUPLICATE_WARNING: str
CALLBACK: str
ONE_SHOT: str
ONLY_CALLER: str
CALLS: Final = "calls"
ARGUMENTS: Final = "arguments"
DUPLICATE_WARNING: Final = 'Duplicate callback found for "%s:%s"'
CALLBACK: Final = "callback"
ONE_SHOT: Final = "one_shot"
ONLY_CALLER: Final = "only"
def __init__(self) -> None: ...
def add(
self,
Expand All @@ -28,13 +31,24 @@ class CallbackManager:
callback: Callable[..., object],
one_shot: bool = True,
only_caller: object | None = None,
arguments=None,
arguments: Mapping[str, Incomplete] | None = None,
) -> tuple[str | int, str | object]: ...
def clear(self) -> None: ...
def cleanup(self, prefix: str | int) -> bool: ...
def pending(self, prefix: str | int, key: str | object) -> int | None: ...
def process(self, prefix: str | int, key: AMQPValue, caller, *args, **keywords) -> bool: ...
def pending(self, prefix: str | int, key: AMQPValue) -> int | None: ...
def process(
self,
prefix: str | int,
key: AMQPValue,
caller,
*args: Any, # Arguments depends on callbacks stored on self._stack
**keywords: Any,
) -> bool: ...
def remove(
self, prefix: str | int, key: AMQPValue, callback_value: Callable[..., object] | None = None, arguments=None
) -> Literal[True]: ...
def remove_all(self, prefix: str | int, key: AMQPValue) -> None: ...
self,
prefix: str | int,
key: AMQPValue,
callback_value: Callable[..., object] | None = None,
arguments: Mapping[str, Incomplete] | None = None,
) -> bool: ...
def remove_all(self, prefix: str | int, key: AMQPValue) -> Literal[False] | None: ...
36 changes: 19 additions & 17 deletions stubs/pika/pika/channel.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from _typeshed import Incomplete
from collections.abc import Callable
from collections.abc import Callable, Iterable, Mapping
from logging import Logger
from typing import Any, Final
from typing import Final, TypeVar
from typing_extensions import Self

from . import amqp_object
from .callback import CallbackManager
from .connection import Connection
from .data import _ArgumentMapping
from .exchange_type import ExchangeType
from .frame import Body, Header, Method
from .spec import Basic, BasicProperties, Confirm, Exchange, Queue, Tx

_Method = TypeVar("_Method", bound=amqp_object.Method)

LOGGER: Logger
MAX_CHANNELS: Final[int]
MAX_CHANNELS: Final = 65535

class Channel:
CLOSED: Final = 0
Expand All @@ -27,11 +29,11 @@ class Channel:

def __init__(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 = True) -> None: ...
def add_on_cancel_callback(self, callback) -> None: ...
def add_on_close_callback(self, callback) -> None: ...
def add_on_flow_callback(self, callback) -> None: ...
def add_on_return_callback(self, callback) -> None: ...
def add_callback(self, callback: Callable[..., object], replies: Iterable[Incomplete], one_shot: bool = True) -> None: ...
def add_on_cancel_callback(self, callback: Callable[[Method[Basic.Cancel]], object]) -> None: ...
def add_on_close_callback(self, callback: Callable[[Channel, Exception], object]) -> None: ...
def add_on_flow_callback(self, callback: Callable[[bool], object]) -> None: ...
def add_on_return_callback(self, callback: Callable[[Channel, Basic.Return, BasicProperties, bytes], object]) -> None: ...
def basic_ack(self, delivery_tag: int = 0, multiple: bool = False) -> None: ...
def basic_cancel(
self, consumer_tag: str = "", callback: Callable[[Method[Basic.CancelOk]], object] | None = None
Expand All @@ -43,7 +45,7 @@ class Channel:
auto_ack: bool = False,
exclusive: bool = False,
consumer_tag: str | None = None,
arguments: _ArgumentMapping | None = None,
arguments: Mapping[str, Incomplete] | None = None,
callback: Callable[[Method[Basic.ConsumeOk]], object] | None = None,
) -> str: ...
def basic_get(
Expand Down Expand Up @@ -82,7 +84,7 @@ class Channel:
destination: str,
source: str,
routing_key: str = "",
arguments: _ArgumentMapping | None = None,
arguments: Mapping[str, Incomplete] | None = None,
callback: Callable[[Method[Exchange.BindOk]], object] | None = None,
) -> None: ...
def exchange_declare(
Expand All @@ -93,7 +95,7 @@ class Channel:
durable: bool = False,
auto_delete: bool = False,
internal: bool = False,
arguments: _ArgumentMapping | None = None,
arguments: Mapping[str, Incomplete] | None = None,
callback: Callable[[Method[Exchange.DeclareOk]], object] | None = None,
) -> None: ...
def exchange_delete(
Expand All @@ -107,7 +109,7 @@ class Channel:
destination: str | None = None,
source: str | None = None,
routing_key: str = "",
arguments: _ArgumentMapping | None = None,
arguments: Mapping[str, Incomplete] | None = None,
callback: Callable[[Method[Exchange.UnbindOk]], object] | None = None,
) -> None: ...
def flow(self, active: bool, callback: Callable[[bool], object] | None = None) -> None: ...
Expand All @@ -125,7 +127,7 @@ class Channel:
queue: str,
exchange: str,
routing_key: str | None = None,
arguments: _ArgumentMapping | None = None,
arguments: Mapping[str, Incomplete] | None = None,
callback: Callable[[Method[Queue.BindOk]], object] | None = None,
) -> None: ...
def queue_declare(
Expand All @@ -135,7 +137,7 @@ class Channel:
durable: bool = False,
exclusive: bool = False,
auto_delete: bool = False,
arguments: _ArgumentMapping | None = None,
arguments: Mapping[str, Incomplete] | None = None,
callback: Callable[[Method[Queue.DeclareOk]], object] | None = None,
) -> None: ...
def queue_delete(
Expand All @@ -151,7 +153,7 @@ class Channel:
queue: str,
exchange: str | None = None,
routing_key: str | None = None,
arguments: _ArgumentMapping | None = None,
arguments: Mapping[str, Incomplete] | None = None,
callback: Callable[[Method[Queue.UnbindOk]], object] | None = None,
): ...
def tx_commit(self, callback: Callable[[Method[Tx.CommitOk]], object] | None = None) -> None: ...
Expand All @@ -160,4 +162,4 @@ class Channel:

class ContentFrameAssembler:
def __init__(self) -> None: ...
def process(self, frame_value: Method[Any] | Header | Body) -> tuple[Incomplete, Incomplete, bytes] | None: ...
def process(self, frame_value: Method[_Method] | Header | Body) -> tuple[Method[_Method], Header, bytes] | None: ...
88 changes: 46 additions & 42 deletions stubs/pika/pika/connection.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import ssl
from _typeshed import Incomplete
from collections.abc import Callable
from logging import Logger
from typing import Final
from typing import Final, Literal
from typing_extensions import Self

from .callback import CallbackManager
from .channel import Channel
from .compat import AbstractBase
from .credentials import _Credentials
from .credentials import PlainCredentials, _Credentials
from .frame import Method
from .spec import Connection as SpecConnection

PRODUCT: str
PRODUCT: Final = "Pika Python Client Library"
LOGGER: Logger

class Parameters:
Expand All @@ -35,26 +35,26 @@ class Parameters:
"_virtual_host",
"_tcp_options",
)
DEFAULT_USERNAME: str
DEFAULT_PASSWORD: str
DEFAULT_BLOCKED_CONNECTION_TIMEOUT: None
DEFAULT_CHANNEL_MAX: int
DEFAULT_CLIENT_PROPERTIES: None
DEFAULT_CREDENTIALS: Incomplete
DEFAULT_CONNECTION_ATTEMPTS: int
DEFAULT_FRAME_MAX: int
DEFAULT_USERNAME: Final = "guest"
DEFAULT_PASSWORD: Final = "guest"
DEFAULT_BLOCKED_CONNECTION_TIMEOUT: Final = None
DEFAULT_CHANNEL_MAX: Final = 65535
DEFAULT_CLIENT_PROPERTIES: Final = None
DEFAULT_CREDENTIALS: Final[PlainCredentials]
DEFAULT_CONNECTION_ATTEMPTS: Final = 1
DEFAULT_FRAME_MAX: Final = 131072
DEFAULT_HEARTBEAT_TIMEOUT: None
DEFAULT_HOST: str
DEFAULT_LOCALE: str
DEFAULT_PORT: int
DEFAULT_RETRY_DELAY: float
DEFAULT_SOCKET_TIMEOUT: float
DEFAULT_STACK_TIMEOUT: float
DEFAULT_SSL: bool
DEFAULT_SSL_OPTIONS: None
DEFAULT_SSL_PORT: int
DEFAULT_VIRTUAL_HOST: str
DEFAULT_TCP_OPTIONS: None
DEFAULT_HOST: Final = "localhost"
DEFAULT_LOCALE: Final = "en_US"
DEFAULT_PORT: Final = 5672
DEFAULT_RETRY_DELAY: Final = 2.0
DEFAULT_SOCKET_TIMEOUT: Final = 10.0
DEFAULT_STACK_TIMEOUT: Final = 15.0
DEFAULT_SSL: Final = False
DEFAULT_SSL_OPTIONS: Final = None
DEFAULT_SSL_PORT: Final = 5671
DEFAULT_VIRTUAL_HOST: Final = "/"
DEFAULT_TCP_OPTIONS: Final = None
def __init__(self) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
Expand Down Expand Up @@ -135,13 +135,12 @@ class Parameters:
def virtual_host(self, value: str) -> None: ...

@property
def tcp_options(self) -> dict[Incomplete, Incomplete] | None: ...
def tcp_options(self) -> dict[str, Incomplete] | None: ...
@tcp_options.setter
def tcp_options(self, value: dict[Incomplete, Incomplete] | None) -> None: ...
def tcp_options(self, value: dict[str, Incomplete] | None) -> None: ...

class ConnectionParameters(Parameters):
__slots__ = ()

def __init__(
self,
host: str = ...,
Expand All @@ -158,8 +157,8 @@ class ConnectionParameters(Parameters):
stack_timeout: float | None = ...,
locale: str = ...,
blocked_connection_timeout: float | None = ...,
client_properties: dict[Incomplete, Incomplete] | None = ...,
tcp_options: dict[Incomplete, Incomplete] | None = ...,
client_properties: dict[str, Incomplete] | None = ...,
tcp_options: dict[str, Incomplete] | None = ...,
) -> None: ...

class URLParameters(Parameters):
Expand All @@ -173,22 +172,22 @@ class SSLOptions:
def __init__(self, context: ssl.SSLContext, server_hostname: str | None = None) -> None: ...

class Connection(AbstractBase, metaclass=abc.ABCMeta):
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
ON_CONNECTION_CLOSED: Final = "_on_connection_closed"
ON_CONNECTION_ERROR: Final = "_on_connection_error"
ON_CONNECTION_OPEN_OK: Final = "_on_connection_open_ok"
CONNECTION_CLOSED: Final = 0
CONNECTION_INIT: Final = 1
CONNECTION_PROTOCOL: Final = 2
CONNECTION_START: Final = 3
CONNECTION_TUNE: Final = 4
CONNECTION_OPEN: Final = 5
CONNECTION_CLOSING: Final = 6
connection_state: Literal[0, 1, 2, 3, 4, 5, 6] # one of the constants above
params: Parameters
callbacks: CallbackManager
server_capabilities: Incomplete
server_properties: Incomplete
known_hosts: Incomplete
server_capabilities: dict[str, bool] | None
server_properties: dict[str, Incomplete] | None
known_hosts: str | None
def __init__(
self,
parameters: Parameters | None = None,
Expand All @@ -209,7 +208,12 @@ class Connection(AbstractBase, metaclass=abc.ABCMeta):
def channel(
self, channel_number: int | None = None, on_open_callback: Callable[[Channel], object] | None = None
) -> Channel: ...
def update_secret(self, new_secret, reason, callback=None) -> None: ...
def update_secret(
self,
new_secret: str | bytes,
reason: str | bytes,
callback: Callable[[Method[SpecConnection.UpdateSecretOk]], object] | None = None,
) -> None: ...
def close(self, reply_code: int = 200, reply_text: str = "Normal shutdown") -> None: ...
@property
def is_closed(self) -> bool: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/pika/pika/data.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ _Value: TypeAlias = str | bytes | bool | int | Decimal | datetime | _ArgumentMap
_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 decode_short_string(encoded: bytes, offset: int) -> tuple[str | bytes, 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_table(encoded: bytes, offset: int) -> tuple[dict[str | bytes, _Value], int]: ...
def decode_value(encoded: bytes, offset: int) -> tuple[_Value, int]: ...
Loading