Skip to content

Commit 1b1a35e

Browse files
committed
[pika] Update to 1.4.*
1 parent 2d78fda commit 1b1a35e

14 files changed

Lines changed: 183 additions & 115 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
# Behind a TYPE_CHECKING guard at runtime.
2+
pika.adapters.select_connection.SELECT_ERROR_T
3+
pika.adapters.select_connection.POLLER_PARAMS
4+
15
# The implementation has defaults for the arguments that would make the
26
# created instances unusable, so we require the arguments in the stub.
37
pika.spec.Queue.DeclareOk.__init__
48

9+
# Type hackary that is unnecessary in the stubs.
10+
pika.connection.ConnectionParameters.DefaultT
11+
pika.connection.ConnectionParameters.T
12+
513
# Arguments have a sentinel default, which is not reflected in the stubs.
614
pika.connection.ConnectionParameters.__init__

stubs/pika/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "1.3.*"
1+
version = "1.4.*"
22
upstream-repository = "https://github.com/pika/pika"
33
stub-distribution = "types-pika-ts" # https://github.com/python/typeshed/issues/9246
44
extra-description = """\

stubs/pika/pika/__init__.pyi

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,17 @@ from pika.delivery_mode import DeliveryMode as DeliveryMode
1313
from pika.spec import BasicProperties as BasicProperties
1414

1515
__version__: Final[str]
16+
17+
__all__ = [
18+
"adapters",
19+
"AMQPConnectionWorkflow",
20+
"BaseConnection",
21+
"BasicProperties",
22+
"BlockingConnection",
23+
"ConnectionParameters",
24+
"DeliveryMode",
25+
"PlainCredentials",
26+
"SelectConnection",
27+
"SSLOptions",
28+
"URLParameters",
29+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from pika.adapters.asyncio_connection import AsyncioConnection as AsyncioConnection
12
from pika.adapters.base_connection import BaseConnection as BaseConnection
23
from pika.adapters.blocking_connection import BlockingConnection as BlockingConnection
34
from pika.adapters.select_connection import IOLoop as IOLoop, SelectConnection as SelectConnection
5+
6+
__all__ = ["AsyncioConnection", "BaseConnection", "BlockingConnection", "SelectConnection", "IOLoop"]
Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
from asyncio import AbstractEventLoop
2-
from collections.abc import Callable
1+
from _typeshed import Incomplete
2+
from asyncio import AbstractEventLoop, Future, Handle
3+
from collections.abc import Callable, Sequence
34
from logging import Logger
45
from typing_extensions import Self
56

6-
from ..connection import Parameters
7+
from ..connection import Connection, Parameters
78
from .base_connection import BaseConnection
8-
from .utils import connection_workflow, io_services_utils, nbio_interface
9+
from .utils import io_services_utils
10+
from .utils.connection_workflow import AbstractAMQPConnectionWorkflow, AMQPConnectorException
11+
from .utils.nbio_interface import AbstractFileDescriptorServices, AbstractIOReference, AbstractIOServices, AbstractTimerReference
912

1013
LOGGER: Logger
1114

@@ -22,35 +25,44 @@ class AsyncioConnection(BaseConnection):
2225
@classmethod
2326
def create_connection(
2427
cls,
25-
connection_configs,
26-
on_done,
28+
connection_configs: Sequence[Parameters],
29+
on_done: Callable[[Connection | AMQPConnectorException], object],
2730
custom_ioloop: AbstractEventLoop | None = None,
28-
workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = None,
29-
): ...
31+
workflow: AbstractAMQPConnectionWorkflow | None = None,
32+
) -> AbstractAMQPConnectionWorkflow: ...
3033

3134
class _AsyncioIOServicesAdapter(
3235
io_services_utils.SocketConnectionMixin,
3336
io_services_utils.StreamingConnectionMixin,
34-
nbio_interface.AbstractIOServices,
35-
nbio_interface.AbstractFileDescriptorServices,
37+
AbstractIOServices,
38+
AbstractFileDescriptorServices,
3639
):
3740
def __init__(self, loop: AbstractEventLoop | None = None) -> None: ...
38-
def get_native_ioloop(self): ...
41+
def get_native_ioloop(self) -> AbstractEventLoop: ...
3942
def close(self) -> None: ...
4043
def run(self) -> None: ...
4144
def stop(self) -> None: ...
42-
def add_callback_threadsafe(self, callback) -> None: ...
43-
def call_later(self, delay, callback): ...
44-
def getaddrinfo(self, host, port, on_done, family: int = 0, socktype: int = 0, proto: int = 0, flags: int = 0): ...
45-
def set_reader(self, fd, on_readable) -> None: ...
46-
def remove_reader(self, fd): ...
47-
def set_writer(self, fd, on_writable) -> None: ...
48-
def remove_writer(self, fd): ...
45+
def add_callback_threadsafe(self, callback: Callable[[], object]) -> None: ...
46+
def call_later(self, delay: float, callback: Callable[[], object]) -> _TimerHandle: ...
47+
def getaddrinfo(
48+
self,
49+
host: str,
50+
port: int,
51+
on_done: Callable[..., object],
52+
family: int = 0,
53+
socktype: int = 0,
54+
proto: int = 0,
55+
flags: int = 0,
56+
) -> AbstractIOReference: ...
57+
def set_reader(self, fd: int, on_readable: Callable[[], object]) -> None: ...
58+
def remove_reader(self, fd: int) -> bool: ...
59+
def set_writer(self, fd: int, on_writable: Callable[[], object]) -> None: ...
60+
def remove_writer(self, fd: int) -> bool: ...
4961

50-
class _TimerHandle(nbio_interface.AbstractTimerReference):
51-
def __init__(self, handle) -> None: ...
62+
class _TimerHandle(AbstractTimerReference):
63+
def __init__(self, handle: Handle) -> None: ...
5264
def cancel(self) -> None: ...
5365

54-
class _AsyncioIOReference(nbio_interface.AbstractIOReference):
55-
def __init__(self, future, on_done) -> None: ...
56-
def cancel(self): ...
66+
class _AsyncioIOReference(AbstractIOReference):
67+
def __init__(self, future: Future[Incomplete], on_done: Callable[[BaseConnection | BaseException], object]) -> None: ...
68+
def cancel(self) -> bool: ...

stubs/pika/pika/adapters/base_connection.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ from collections.abc import Callable
44
from logging import Logger
55
from typing_extensions import Self
66

7-
from ..adapters.utils import nbio_interface
8-
from ..connection import Connection
7+
from ..adapters.utils.nbio_interface import AbstractIOServices, AbstractStreamProtocol
8+
from ..connection import Connection, Parameters
99

1010
LOGGER: Logger
1111

1212
class BaseConnection(Connection, metaclass=abc.ABCMeta):
1313
def __init__(
1414
self,
15-
parameters,
15+
parameters: Parameters | None,
1616
on_open_callback: Callable[[Self], object] | None,
1717
on_open_error_callback: Callable[[Self, BaseException], object] | None,
1818
on_close_callback: Callable[[Self, BaseException], object] | None,
19-
nbio,
20-
internal_connection_workflow: bool,
19+
nbio: AbstractIOServices,
20+
internal_connection_workflow: bool = True,
2121
) -> None: ...
2222
@classmethod
2323
@abc.abstractmethod
2424
def create_connection(cls, connection_configs, on_done, custom_ioloop=None, workflow=None): ...
2525
@property
2626
def ioloop(self): ...
2727

28-
class _StreamingProtocolShim(nbio_interface.AbstractStreamProtocol):
28+
class _StreamingProtocolShim(AbstractStreamProtocol):
2929
connection_made: Incomplete
3030
connection_lost: Incomplete
3131
eof_received: Incomplete

stubs/pika/pika/adapters/blocking_connection.pyi

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from _typeshed import Incomplete, Unused
2-
from collections.abc import Generator, Sequence
2+
from collections.abc import Callable, Generator, Sequence
33
from logging import Logger
44
from types import TracebackType
5-
from typing import NamedTuple
5+
from typing import Any, NamedTuple, TypeVar
66
from typing_extensions import Self
77

88
from ..connection import Parameters
9-
from ..data import _ArgumentMapping
109
from ..exchange_type import ExchangeType
11-
from ..spec import BasicProperties
10+
from ..frame import Method
11+
from ..spec import Basic, BasicProperties, Connection, Exchange, Queue, Tx
12+
13+
T = TypeVar("T", bound=Connection.Blocked | Connection.Unblocked)
1214

1315
LOGGER: Logger
1416

@@ -189,19 +191,33 @@ class BlockingChannel:
189191
def add_on_cancel_callback(self, callback) -> None: ...
190192
def add_on_return_callback(self, callback): ...
191193
def basic_consume(
192-
self, queue, on_message_callback, auto_ack: bool = False, exclusive: bool = False, consumer_tag=None, arguments=None
193-
): ...
194-
def basic_cancel(self, consumer_tag): ...
194+
self,
195+
queue: str,
196+
on_message_callback: Callable[[BlockingChannel, Basic.Deliver, BasicProperties, bytes], object],
197+
auto_ack: bool = False,
198+
exclusive: bool = False,
199+
consumer_tag: str | None = None,
200+
arguments: dict[str, Any] | None = None,
201+
) -> str: ...
202+
def basic_cancel(self, consumer_tag: str) -> Sequence[tuple[Basic.Deliver, BasicProperties, bytes]]: ...
195203
def start_consuming(self) -> None: ...
196-
def stop_consuming(self, consumer_tag=None) -> None: ...
204+
def stop_consuming(self, consumer_tag: str | None = None) -> None: ...
197205
def consume(
198-
self, queue, auto_ack: bool = False, exclusive: bool = False, arguments=None, inactivity_timeout=None
199-
) -> Generator[Incomplete]: ...
200-
def get_waiting_message_count(self): ...
201-
def cancel(self): ...
206+
self,
207+
queue: str,
208+
auto_ack: bool = False,
209+
exclusive: bool = False,
210+
arguments: dict[str, Any] | None = None,
211+
inactivity_timeout: float | None = None,
212+
consumer_tag: str | None = None,
213+
) -> Generator[tuple[Basic.Deliver | None, BasicProperties | None, bytes | None]]: ...
214+
def get_waiting_message_count(self) -> int: ...
215+
def cancel(self) -> int: ...
202216
def basic_ack(self, delivery_tag: int = 0, multiple: bool = False) -> None: ...
203217
def basic_nack(self, delivery_tag: int = 0, multiple: bool = False, requeue: bool = True) -> None: ...
204-
def basic_get(self, queue, auto_ack: bool = False): ...
218+
def basic_get(
219+
self, queue: str, auto_ack: bool = False
220+
) -> tuple[Basic.GetOk | None, BasicProperties | None, bytes | None]: ...
205221
def basic_publish(
206222
self,
207223
exchange: str,
@@ -222,24 +238,36 @@ class BlockingChannel:
222238
durable: bool = False,
223239
auto_delete: bool = False,
224240
internal: bool = False,
225-
arguments: _ArgumentMapping | None = None,
226-
): ...
227-
def exchange_delete(self, exchange: str | None = None, if_unused: bool = False): ...
228-
def exchange_bind(self, destination, source, routing_key: str = "", arguments=None): ...
229-
def exchange_unbind(self, destination=None, source=None, routing_key: str = "", arguments=None): ...
241+
arguments: dict[str, Any] | None = None,
242+
) -> None: ...
243+
def exchange_delete(self, exchange: str | None = None, if_unused: bool = False) -> Method[Exchange.DeleteOk]: ...
244+
def exchange_bind(
245+
self, destination: str, source: str, routing_key: str = "", arguments: dict[str, Any] | None = None
246+
) -> Method[Exchange.BindOk]: ...
247+
def exchange_unbind(
248+
self,
249+
destination: str | None = None,
250+
source: str | None = None,
251+
routing_key: str = "",
252+
arguments: dict[str, Any] | None = None,
253+
) -> Method[Exchange.UnbindOk]: ...
230254
def queue_declare(
231255
self,
232-
queue,
256+
queue: str,
233257
passive: bool = False,
234258
durable: bool = False,
235259
exclusive: bool = False,
236260
auto_delete: bool = False,
237-
arguments=None,
238-
): ...
239-
def queue_delete(self, queue, if_unused: bool = False, if_empty: bool = False): ...
240-
def queue_purge(self, queue): ...
241-
def queue_bind(self, queue, exchange, routing_key=None, arguments=None): ...
242-
def queue_unbind(self, queue, exchange=None, routing_key=None, arguments=None): ...
243-
def tx_select(self): ...
244-
def tx_commit(self): ...
245-
def tx_rollback(self): ...
261+
arguments: dict[str, Any] | None = None,
262+
) -> Method[Queue.DeclareOk]: ...
263+
def queue_delete(self, queue: str, if_unused: bool = False, if_empty: bool = False) -> Method[Queue.DeleteOk]: ...
264+
def queue_purge(self, queue: str) -> Method[Queue.PurgeOk]: ...
265+
def queue_bind(
266+
self, queue: str, exchange: str, routing_key: str | None = None, arguments: dict[str, Any] | None = None
267+
) -> Method[Queue.BindOk]: ...
268+
def queue_unbind(
269+
self, queue: str, exchange: str, routing_key: str | None = None, arguments: dict[str, Any] | None = None
270+
) -> Method[Queue.UnbindOk]: ...
271+
def tx_select(self) -> Method[Tx.SelectOk]: ...
272+
def tx_commit(self) -> Method[Tx.CommitOk]: ...
273+
def tx_rollback(self) -> Method[Tx.RollbackOk]: ...

stubs/pika/pika/adapters/select_connection.pyi

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import abc
2+
import select
23
from _typeshed import Incomplete
4+
from collections.abc import Callable
35
from logging import Logger
6+
from typing import Final, Literal, TypeAlias, TypedDict
47

58
import pika.compat
69
from pika.adapters.base_connection import BaseConnection
710
from pika.adapters.utils.selector_ioloop_adapter import AbstractSelectorIOLoop
811

12+
SELECT_ERROR_T: TypeAlias = OSError | InterruptedError | select.error
13+
14+
class POLLER_PARAMS(TypedDict):
15+
get_wait_seconds: Callable[[], float | None]
16+
process_timeouts: Callable[[], object]
17+
918
LOGGER: Logger
10-
SELECT_TYPE: Incomplete
19+
SELECT_TYPE: Literal["epoll", "kqueue", "poll"] | None
1120

1221
class SelectConnection(BaseConnection):
1322
def __init__(
@@ -43,9 +52,10 @@ class _Timer:
4352
def process_timeouts(self) -> None: ...
4453

4554
class PollEvents:
46-
READ: Incomplete
47-
WRITE: Incomplete
48-
ERROR: Incomplete
55+
READ: Final[int]
56+
WRITE: Final[int]
57+
ERROR: Final[int]
58+
HANGUP: Final[int]
4959

5060
class IOLoop(AbstractSelectorIOLoop):
5161
READ: Incomplete

stubs/pika/pika/adapters/twisted_connection.pyi

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# We don't want to force it as a dependency but that means we also can't test it with type-checkers given the current setup.
33

44
from _typeshed import Incomplete
5+
from collections.abc import Callable
56
from logging import Logger
6-
from typing import Generic, NamedTuple, TypeVar
7+
from typing import Any, Generic, NamedTuple, TypeVar
78

8-
import pika.connection
9-
from pika.adapters.utils import nbio_interface
9+
from pika.adapters.utils.nbio_interface import AbstractTimerReference
1010
from twisted.internet.base import DelayedCall # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
1111
from twisted.internet.defer import ( # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
1212
Deferred,
@@ -16,6 +16,8 @@ from twisted.internet.interfaces import ITransport # type: ignore[import-not-fo
1616
from twisted.internet.protocol import Protocol # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
1717
from twisted.python.failure import Failure # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
1818

19+
from ..connection import Connection, Parameters
20+
1921
_T = TypeVar("_T")
2022

2123
LOGGER: Logger
@@ -93,13 +95,9 @@ class TwistedChannel:
9395
self, exchange: Incomplete | None = ..., if_unused: bool = ...
9496
) -> Deferred[Incomplete | Failure | BaseException | None]: ...
9597
def exchange_unbind(
96-
self,
97-
destination: Incomplete | None = ...,
98-
source: Incomplete | None = ...,
99-
routing_key: str = ...,
100-
arguments: Incomplete | None = ...,
98+
self, destination: str, source: str, routing_key: str = "", arguments: dict[str, Any] | None = None
10199
) -> Deferred[Incomplete | Failure | BaseException | None]: ...
102-
def flow(self, active) -> Deferred[Incomplete | Failure | BaseException | None]: ...
100+
def flow(self, active: bool = True) -> Deferred[Incomplete | Failure | BaseException | None]: ...
103101
def open(self): ...
104102
def queue_bind(
105103
self, queue, exchange, routing_key: Incomplete | None = ..., arguments: Incomplete | None = ...
@@ -118,14 +116,21 @@ class TwistedChannel:
118116
) -> Deferred[Incomplete | Failure | BaseException | None]: ...
119117
def queue_purge(self, queue) -> Deferred[Incomplete | Failure | BaseException | None]: ...
120118
def queue_unbind(
121-
self, queue, exchange: Incomplete | None = ..., routing_key: Incomplete | None = ..., arguments: Incomplete | None = ...
119+
self, queue: str, exchange: str | None, routing_key: str | None = None, arguments: dict[str, Any] | None = None
122120
) -> Deferred[Incomplete | Failure | BaseException | None]: ...
123121
def tx_commit(self) -> Deferred[Incomplete | Failure | BaseException | None]: ...
124122
def tx_rollback(self) -> Deferred[Incomplete | Failure | BaseException | None]: ...
125123
def tx_select(self) -> Deferred[Incomplete | Failure | BaseException | None]: ...
126124

127-
class _TwistedConnectionAdapter(pika.connection.Connection):
128-
def __init__(self, parameters, on_open_callback, on_open_error_callback, on_close_callback, custom_reactor) -> None: ...
125+
class _TwistedConnectionAdapter(Connection):
126+
def __init__(
127+
self,
128+
parameters: Parameters | None,
129+
on_open_callback: Callable[[Connection], object] | None,
130+
on_open_error_callback: Callable[[Connection, Exception], object] | None,
131+
on_close_callback: Callable[[Connection, Exception], object] | None,
132+
custom_reactor: Incomplete | None = None,
133+
) -> None: ...
129134
def connection_made(self, transport: ITransport) -> None: ...
130135
def connection_lost(self, error: Exception) -> None: ...
131136
def data_received(self, data) -> None: ...
@@ -145,6 +150,6 @@ class TwistedProtocolConnection(Protocol): # pyright: ignore[reportUntypedBaseC
145150
def makeConnection(self, transport: ITransport) -> None: ...
146151
def connectionReady(self): ...
147152

148-
class _TimerHandle(nbio_interface.AbstractTimerReference):
153+
class _TimerHandle(AbstractTimerReference):
149154
def __init__(self, handle: DelayedCall) -> None: ...
150155
def cancel(self) -> None: ...

0 commit comments

Comments
 (0)