From e92fc1be28911b57eabd97fbae7592fa7322a54f Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Mon, 17 Jan 2022 13:33:21 -0600 Subject: [PATCH 01/11] Update linting/testing configs Copy configs from typeshed project Add stubtest to github action --- .flake8 | 27 ++++++++++++++++- .github/workflows/check.yaml | 54 +++++++++++++++++++-------------- mypy.ini | 2 ++ pyproject.toml | 32 ++++++++++++++++++++ requirements-dev.txt | 58 ++++++++++++++++++++++++++++++++++++ setup.cfg | 7 +++-- 6 files changed, 154 insertions(+), 26 deletions(-) create mode 100644 pyproject.toml create mode 100644 requirements-dev.txt diff --git a/.flake8 b/.flake8 index 47f4fc5..480f13d 100644 --- a/.flake8 +++ b/.flake8 @@ -1,5 +1,30 @@ +# The following rules are incompatible with or enforced by black: +# E203 whitespace before ':' -- scripts only +# E301 expected 1 blank line -- stubs only +# E302 expected 2 blank lines -- stubs only +# E305 expected 2 blank lines -- stubs only +# E501 line too long + +# Some rules are considered irrelevant to stub files: +# E701 multiple statements on one line (colon) -- disallows "..." on the same line +# F401 imported but unused -- does not recognize re-exports +# https://github.com/PyCQA/pyflakes/issues/474 +# F822 undefined name in __all__ -- flake8 does not recognize 'foo: Any' +# https://github.com/PyCQA/pyflakes/issues/533 + +# Rules that are out of the control of stub authors: +# E741 ambiguous variable name +# F403 import *' used; unable to detect undefined names +# F405 defined from star imports + [flake8] -max-line-length = 99 +per-file-ignores = + *.py: E203, E501 + *.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822 + typing.pyi: E301, E302, E305, E501, E701, E741, F401, F403, F405, F822 + exclude = .venv, + .idea, + .mypy_cache, .git diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index da7b799..530380f 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -1,32 +1,42 @@ name: Check -on: [push, pull_request] +on: + push: + branches: [ $default-branch ] + pull_request: + branches: [ $default-branch ] jobs: check: + name: Run tests runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10"] steps: + - uses: actions/checkout@v2 - - uses: actions/checkout@v2 - - - name: Set up Python 3.8 - uses: actions/setup-python@v1 - with: - python-version: 3.8 - - - name: Cache dependencies - uses: actions/cache@v1 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('setup.cfg') }} - restore-keys: | - ${{ runner.os }}-pip- - - - name: Perform checks - run: | - python -m pip install --upgrade pip - pip install -e .[dev] - flake8 pika-stubs - mypy -p pika-stubs --strict + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: 'requirements-dev.txt' + + - name: Update pip + run: python -m pip install -U pip + + - name: Install dependencies + run: pip install -r requirements-dev.txt + + - name: Lint with flake8 + run: flake8 + + - name: Check stub files with mypy + run: mypy --strict -p pika-stubs + + - name: Stubtest + run: stubtest --concise pika diff --git a/mypy.ini b/mypy.ini index 3f4ca54..2fa095a 100644 --- a/mypy.ini +++ b/mypy.ini @@ -8,5 +8,7 @@ warn_unused_ignores = True warn_unused_configs = True warn_unreachable = True +show_error_codes = True + files = pika-stubs diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e7350d7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,32 @@ +[tool.black] +line-length = 130 +target-version = ['py37'] +include = '\.pyi?$' +exclude = ''' +( + /( + \.eggs # exclude a few common directories in the + | \.git # root of the project + | \.mypy_cache + | \.tox + | \.venv + | _build + | build + | dist + )/ +) +''' +skip_magic_trailing_comma = true + +[tool.isort] +profile = "black" +src_paths = [ + "pika-stubs", +] +combine_as_imports = true +line_length = 130 +force_single_line = true +use_parentheses = true +extra_standard_library = [ + "typing_extensions", +] diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..e0bd218 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,58 @@ +# +# This file is autogenerated by pip-compile with python 3.10 +# To update, run: +# +# pip-compile --extra=dev --output-file=requirements-dev.txt setup.cfg +# +attrs==21.4.0 + # via + # automat + # flake8-pyi + # twisted +automat==20.2.0 + # via twisted +constantly==15.1.0 + # via twisted +flake8==4.0.1 + # via + # flake8-pyi + # pika-stubs (setup.cfg) +flake8-pyi==20.10.0 + # via pika-stubs (setup.cfg) +hyperlink==21.0.0 + # via twisted +idna==3.3 + # via hyperlink +incremental==21.3.0 + # via twisted +mccabe==0.6.1 + # via flake8 +mypy==0.931 + # via pika-stubs (setup.cfg) +mypy-extensions==0.4.3 + # via mypy +pika==1.2.0 + # via pika-stubs (setup.cfg) +pycodestyle==2.8.0 + # via flake8 +pyflakes==2.4.0 + # via + # flake8 + # flake8-pyi +six==1.16.0 + # via automat +tomli==2.0.0 + # via mypy +tornado==6.1 + # via pika-stubs (setup.cfg) +twisted==21.7.0 + # via pika-stubs (setup.cfg) +typing-extensions==4.0.1 + # via + # mypy + # twisted +zope.interface==5.4.0 + # via twisted + +# The following packages are considered to be unsafe in a requirements file: +# setuptools diff --git a/setup.cfg b/setup.cfg index 0aa77ea..0c5890b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,8 +25,9 @@ install_requires = [options.extras_require] dev = - flake8~=3.8.3 - mypy~=0.780 + flake8~=4.0.0 + flake8-pyi + mypy~=0.900 + pika==1.2.0 tornado twisted - gevent From c6b481045013a114dcec521daeb6365b87a55808 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Mon, 17 Jan 2022 13:41:03 -0600 Subject: [PATCH 02/11] CI: restore `on` parameter --- .github/workflows/check.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 530380f..b2b8aa8 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -1,10 +1,6 @@ name: Check -on: - push: - branches: [ $default-branch ] - pull_request: - branches: [ $default-branch ] +on: [push, pull_request] jobs: check: From dbea1018387fc6b7c77fa275eddc5753841ab7b0 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Mon, 17 Jan 2022 13:47:18 -0600 Subject: [PATCH 03/11] linting: fix flake8 failures --- pika-stubs/adapters/asyncio_connection.pyi | 10 +++++----- pika-stubs/adapters/tornado_connection.pyi | 10 +++++----- pika-stubs/adapters/twisted_connection.pyi | 3 --- pika-stubs/adapters/utils/io_services_utils.pyi | 4 ++-- pika-stubs/adapters/utils/nbio_interface.pyi | 4 ++-- pika-stubs/compat.pyi | 4 +--- pika-stubs/spec.pyi | 4 ++-- 7 files changed, 17 insertions(+), 22 deletions(-) diff --git a/pika-stubs/adapters/asyncio_connection.pyi b/pika-stubs/adapters/asyncio_connection.pyi index ba5243e..fd8c03e 100644 --- a/pika-stubs/adapters/asyncio_connection.pyi +++ b/pika-stubs/adapters/asyncio_connection.pyi @@ -14,11 +14,11 @@ class AsyncioConnection(base_connection.BaseConnection[asyncio.AbstractEventLoop def __init__( self, - parameters: Optional[connection.Parameters] = None, - on_open_callback: Optional[_OnOpenCallback] = None, - on_open_error_callback: Optional[_OnOpenErrorCallback] = None, - on_close_callback: Optional[_OnCloseCallback] = None, - custom_ioloop: Optional[asyncio.AbstractEventLoop] = None, + parameters: Optional[connection.Parameters] = ..., + on_open_callback: Optional[_OnOpenCallback] = ..., + on_open_error_callback: Optional[_OnOpenErrorCallback] = ..., + on_close_callback: Optional[_OnCloseCallback] = ..., + custom_ioloop: Optional[asyncio.AbstractEventLoop] = ..., internal_connection_workflow: bool = ..., ) -> None: ... diff --git a/pika-stubs/adapters/tornado_connection.pyi b/pika-stubs/adapters/tornado_connection.pyi index 3b4d384..579f76d 100644 --- a/pika-stubs/adapters/tornado_connection.pyi +++ b/pika-stubs/adapters/tornado_connection.pyi @@ -15,16 +15,16 @@ class TornadoConnection(base_connection.BaseConnection[tornado.ioloop.IOLoop]): def __init__( self, - parameters: Optional[connection.Parameters] = None, - on_open_callback: Optional[_OnOpenCallback] = None, - on_open_error_callback: Optional[_OnOpenErrorCallback] = None, - on_close_callback: Optional[_OnCloseCallback] = None, + parameters: Optional[connection.Parameters] = ..., + on_open_callback: Optional[_OnOpenCallback] = ..., + on_open_error_callback: Optional[_OnOpenErrorCallback] = ..., + on_close_callback: Optional[_OnCloseCallback] = ..., custom_ioloop: Optional[ Union[ tornado.ioloop.IOLoop, nbio_interface.AbstractIOServices, ], - ] = None, + ] = ..., internal_connection_workflow: bool = ..., ) -> None: ... diff --git a/pika-stubs/adapters/twisted_connection.pyi b/pika-stubs/adapters/twisted_connection.pyi index 406400f..06d54e8 100644 --- a/pika-stubs/adapters/twisted_connection.pyi +++ b/pika-stubs/adapters/twisted_connection.pyi @@ -54,9 +54,7 @@ class ReceivedMessage(NamedTuple): body: bytes - class TwistedChannel: - on_closed: Deferred[Union[twisted.python.failure.Failure, Exception, str]] def __init__(self, channel: Channel) -> None: ... @@ -89,7 +87,6 @@ class TwistedChannel: def basic_ack(self, delivery_tag: int = ..., multiple: bool = ...) -> None: ... def basic_cancel(self, consumer_tag: str = ...) -> None: ... - # ReceivedMessage.method: spec.Basic.Deliver def basic_consume( self, diff --git a/pika-stubs/adapters/utils/io_services_utils.pyi b/pika-stubs/adapters/utils/io_services_utils.pyi index bea5e4b..c5a71cc 100644 --- a/pika-stubs/adapters/utils/io_services_utils.pyi +++ b/pika-stubs/adapters/utils/io_services_utils.pyi @@ -35,6 +35,6 @@ class StreamingConnectionMixin: ], None, ], - ssl_context: ssl.SSLContext | None = None, - server_hostname: str | None = None, + ssl_context: ssl.SSLContext | None = ..., + server_hostname: str | None = ..., ) -> nbio_interface.AbstractIOReference: ... diff --git a/pika-stubs/adapters/utils/nbio_interface.pyi b/pika-stubs/adapters/utils/nbio_interface.pyi index bb93d5c..5be595e 100644 --- a/pika-stubs/adapters/utils/nbio_interface.pyi +++ b/pika-stubs/adapters/utils/nbio_interface.pyi @@ -64,8 +64,8 @@ class AbstractIOServices(compat.AbstractBase): ], None, ], - ssl_context: ssl.SSLContext | None = None, - server_hostname: str | None = None, + ssl_context: ssl.SSLContext | None = ..., + server_hostname: str | None = ..., ) -> AbstractIOReference: ... diff --git a/pika-stubs/compat.pyi b/pika-stubs/compat.pyi index b77ba59..8a64d21 100644 --- a/pika-stubs/compat.pyi +++ b/pika-stubs/compat.pyi @@ -1,5 +1,3 @@ import abc - -class AbstractBase(metaclass=abc.ABCMeta): - pass +class AbstractBase(metaclass=abc.ABCMeta): ... diff --git a/pika-stubs/spec.pyi b/pika-stubs/spec.pyi index 7a7bff7..17b74ce 100644 --- a/pika-stubs/spec.pyi +++ b/pika-stubs/spec.pyi @@ -104,7 +104,7 @@ class Connection(amqp_object.Class): challenge: Optional[str] = ... - def __init__(self, challenge: Optional[str] = None) -> None: ... + def __init__(self, challenge: Optional[str] = ...) -> None: ... @property def synchronous(self) -> bool: ... @@ -119,7 +119,7 @@ class Connection(amqp_object.Class): response: Optional[str] = ... - def __init__(self, response: Optional[str] = None) -> None: ... + def __init__(self, response: Optional[str] = ...) -> None: ... @property def synchronous(self) -> bool: ... From cb4451c20e9129e80ae3b85832a62560a4466b63 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Mon, 17 Jan 2022 13:51:01 -0600 Subject: [PATCH 04/11] linting: fix most stubtest failures --- pika-stubs/adapters/twisted_connection.pyi | 2 + .../adapters/utils/io_services_utils.pyi | 2 + pika-stubs/channel.pyi | 12 ++++- pika-stubs/compat.pyi | 43 ++++++++++++++++ pika-stubs/connection.pyi | 51 ++++++++----------- pika-stubs/credentials.pyi | 5 +- pika-stubs/spec.pyi | 3 +- 7 files changed, 85 insertions(+), 33 deletions(-) diff --git a/pika-stubs/adapters/twisted_connection.pyi b/pika-stubs/adapters/twisted_connection.pyi index 06d54e8..9d1fe19 100644 --- a/pika-stubs/adapters/twisted_connection.pyi +++ b/pika-stubs/adapters/twisted_connection.pyi @@ -224,6 +224,8 @@ class TwistedProtocolConnection(twisted.internet.protocol.Protocol): def channel(self, channel_number: Optional[int] = ...) -> Deferred[TwistedChannel]: ... + @property + def is_open(self) -> bool: ... @property def is_closed(self) -> bool: ... diff --git a/pika-stubs/adapters/utils/io_services_utils.pyi b/pika-stubs/adapters/utils/io_services_utils.pyi index c5a71cc..1ba0d1b 100644 --- a/pika-stubs/adapters/utils/io_services_utils.pyi +++ b/pika-stubs/adapters/utils/io_services_utils.pyi @@ -6,6 +6,8 @@ from typing import Any, Callable, Optional, Tuple, Union from . import nbio_interface +def check_callback_arg(callback: Callable, name: str) -> None: ... +def check_fd_arg(fd: int) -> None: ... class SocketConnectionMixin: diff --git a/pika-stubs/channel.pyi b/pika-stubs/channel.pyi index 4627ca6..b945b56 100644 --- a/pika-stubs/channel.pyi +++ b/pika-stubs/channel.pyi @@ -41,7 +41,6 @@ _OnTxSelectCallback = Callable[[spec.Tx.SelectOk], None] class Channel: - CLOSED: int = ... OPENING: int = ... OPEN: int = ... @@ -240,3 +239,14 @@ class Channel: def tx_commit(self, callback: Optional[_OnTxCommitCallback] = ...) -> None: ... def tx_rollback(self, callback: Optional[_OnTxRollbackCallback] = ...) -> None: ... def tx_select(self, callback: Optional[_OnTxSelectCallback] = ...) -> None: ... + +class ContentFrameAssembler: + def __init__(self) -> None: ... + def process( + self, frame_value: frame.Method | frame.Header | frame.Body + ) -> Tuple[frame.Method, frame.Header, bytes] | None: ... + def _finish(self) -> Tuple[frame.Method, frame.Header, bytes]: ... + + def _handle_body_frame(self, body_frame) -> Tuple[frame.Method, frame.Header, bytes] | None: ... + + def _reset(self) -> None: ... diff --git a/pika-stubs/compat.pyi b/pika-stubs/compat.pyi index 8a64d21..7072c66 100644 --- a/pika-stubs/compat.pyi +++ b/pika-stubs/compat.pyi @@ -1,3 +1,46 @@ +from __future__ import annotations + import abc +import re +from typing import Tuple, Type, KeysView, ValuesView, ItemsView, Any + +PY2: bool +PY3: bool +RE_NUM: re.Pattern + +ON_LINUX: bool +ON_OSX: bool +ON_WINDOWS: bool class AbstractBase(metaclass=abc.ABCMeta): ... + +SOCKET_ERROR: Type[Exception] +SOL_TCP: int + +basestring: Tuple[Type[str]] +str_or_bytes: Tuple[Type[str], Type[bytes]] +xrange: Type[range] +unicode_type: Type[str] + + +def time_now() -> float: ... +def dictkeys(dct) -> list[KeysView]: ... +def dictvalues(dct) -> list[ValuesView]: ... +def dict_iteritems(dct) -> ItemsView: ... +def dict_itervalues(dct) -> ValuesView: ... +def byte(*args: int) -> bytes: ... +class long(int): + def __str__(self) -> str: ... + def __repr__(self) -> str: ... +def canonical_str(value) -> str: ... +def is_integer(value: Any) -> bool: ... + +def as_bytes(value: str | bytes) -> bytes: ... +def to_digit(value): ... +def get_linux_version(release_str) -> tuple[int, int, int]: ... + +HAVE_SIGNAL: bool +EINTR_IS_EXPOSED: bool +LINUX_VERSION: Tuple[int, int, int] | None +_LOCALHOST: str +_LOCALHOST_V6: str diff --git a/pika-stubs/connection.pyi b/pika-stubs/connection.pyi index 9d97dbf..15d8447 100644 --- a/pika-stubs/connection.pyi +++ b/pika-stubs/connection.pyi @@ -2,7 +2,7 @@ from __future__ import annotations import numbers import ssl -from typing import Any, Callable, Dict, Mapping, Optional, Union +from typing import Any, Callable, Dict, Mapping, Optional, Union, Type from typing_extensions import Literal @@ -20,10 +20,7 @@ PRODUCT: str _OnHeartbeatTimeoutCallback = Callable[['Connection', numbers.Integral], int] _OnCloseCallback = Callable[['Connection', Exception], None] _OnConnectionBlockedCallback = Callable[ - [ - 'Connection', - frame.Method[spec.Connection.Blocked] - ], + ['Connection', frame.Method[spec.Connection.Blocked]], None, ] _OnConnectionUnblockedCallback = Callable[ @@ -46,7 +43,7 @@ class Parameters: DEFAULT_BLOCKED_CONNECTION_TIMEOUT: Optional[numbers.Real] = ... DEFAULT_CHANNEL_MAX: int = ... DEFAULT_CLIENT_PROPERTIES: Optional[Mapping[str, Any]] = ... - DEFAULT_CREDENTIALS: credentials_.VALID_TYPES = ... + DEFAULT_CREDENTIALS: credentials_._VALID_TYPES = ... DEFAULT_CONNECTION_ATTEMPTS: Literal[1] = ... DEFAULT_FRAME_MAX: int = ... DEFAULT_HEARTBEAT_TIMEOUT: Optional[Union[numbers.Integral, _OnHeartbeatTimeoutCallback]] = ... @@ -79,9 +76,9 @@ class Parameters: @connection_attempts.setter def connection_attempts(self, value: numbers.Integral) -> None: ... @property - def credentials(self) -> credentials_.VALID_TYPES: ... + def credentials(self) -> credentials_._VALID_TYPES: ... @credentials.setter - def credentials(self, value: credentials_.VALID_TYPES) -> None: ... + def credentials(self, value: credentials_._VALID_TYPES) -> None: ... @property def frame_max(self) -> numbers.Integral: ... @frame_max.setter @@ -132,30 +129,26 @@ class Parameters: @tcp_options.setter def tcp_options(self, value: Optional[Mapping[str, Any]]) -> None: ... - class ConnectionParameters(Parameters): - - class _DEFAULT: - ... - + class _DEFAULT: ... def __init__( self, - host: Union[str, _DEFAULT] = ..., - port: Union[int, _DEFAULT] = ..., - virtual_host: Union[str, _DEFAULT] = ..., - credentials: Union[credentials_.VALID_TYPES, _DEFAULT] = ..., - channel_max: Union[int, _DEFAULT] = ..., - frame_max: Union[int, _DEFAULT] = ..., - heartbeat: Union[int, _OnHeartbeatTimeoutCallback, None, _DEFAULT] = ..., - ssl_options: Union[SSLOptions, _DEFAULT] = ..., - connection_attempts: Union[int, _DEFAULT] = ..., - retry_delay: Union[numbers.Real, _DEFAULT] = ..., - socket_timeout: Union[numbers.Real, _DEFAULT] = ..., - stack_timeout: Union[numbers.Real, _DEFAULT] = ..., - locale: Union[str, _DEFAULT] = ..., - blocked_connection_timeout: Union[numbers.Real, None, _DEFAULT] = ..., - client_properties: Union[Mapping[str, Any], None, _DEFAULT] = ..., - tcp_options: Union[Mapping[str, Any], None, _DEFAULT] = ..., + host: Union[str, Type[_DEFAULT]] = ..., + port: Union[int, Type[_DEFAULT]] = ..., + virtual_host: Union[str, Type[_DEFAULT]] = ..., + credentials: Union[credentials_._VALID_TYPES, Type[_DEFAULT]] = ..., + channel_max: Union[int, Type[_DEFAULT]] = ..., + frame_max: Union[int, Type[_DEFAULT]] = ..., + heartbeat: Union[int, _OnHeartbeatTimeoutCallback, None, Type[_DEFAULT]] = ..., + ssl_options: Union[SSLOptions, Type[_DEFAULT]] = ..., + connection_attempts: Union[int, Type[_DEFAULT]] = ..., + retry_delay: Union[numbers.Real, Type[_DEFAULT]] = ..., + socket_timeout: Union[numbers.Real, Type[_DEFAULT]] = ..., + stack_timeout: Union[numbers.Real, Type[_DEFAULT]] = ..., + locale: Union[str, Type[_DEFAULT]] = ..., + blocked_connection_timeout: Union[numbers.Real, None, Type[_DEFAULT]] = ..., + client_properties: Union[Mapping[str, Any], None, Type[_DEFAULT]] = ..., + tcp_options: Union[Mapping[str, Any], None, Type[_DEFAULT]] = ..., **kwargs: Any, ): ... diff --git a/pika-stubs/credentials.pyi b/pika-stubs/credentials.pyi index 29206f9..72ee43d 100644 --- a/pika-stubs/credentials.pyi +++ b/pika-stubs/credentials.pyi @@ -1,4 +1,4 @@ -from typing import Optional, Tuple, Union +from typing import Optional, Tuple, Union, Type from . import spec @@ -35,4 +35,5 @@ class ExternalCredentials: def erase_credentials(self) -> None: ... -VALID_TYPES = Union[PlainCredentials, ExternalCredentials] +_VALID_TYPES = Union[PlainCredentials, ExternalCredentials] +VALID_TYPES: list[_VALID_TYPES] diff --git a/pika-stubs/spec.pyi b/pika-stubs/spec.pyi index 17b74ce..2a77196 100644 --- a/pika-stubs/spec.pyi +++ b/pika-stubs/spec.pyi @@ -4,7 +4,8 @@ from typing import Any, List, Mapping, Optional, Type from typing_extensions import Literal -from . import amqp_object +from . import amqp_object as amqp_object +from .compat import str_or_bytes as str_or_bytes from .exchange_type import ExchangeType PROTOCOL_VERSION: Any From 7071f2b3a3ef6337e4ff84cb8c928b9a8d587394 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Mon, 17 Jan 2022 13:58:21 -0600 Subject: [PATCH 05/11] linting: Fix rest of stubtest This commit fixes the issue pointed out in: https://github.com/hahow/pika-stubs/issues/9 Namely `int` and `float` not (statically) evaluating as subclasses of their abstract types in `numbers`: https://github.com/python/mypy/issues/3186 These abstract types have been replaced with their concrete equivalent. Note that this does not match the code in pika, which *does* compare against e.g. `numbers.Integral` at runtime. But the documented API only mentions concret types (i.e. `int` and `float`) so this is considered a reasonable compromise. addresses hahow/pika-stubs/issues/9 --- pika-stubs/connection.pyi | 53 +++++++++++++++++++-------------------- setup.cfg | 2 +- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/pika-stubs/connection.pyi b/pika-stubs/connection.pyi index 15d8447..ca1b749 100644 --- a/pika-stubs/connection.pyi +++ b/pika-stubs/connection.pyi @@ -1,6 +1,5 @@ from __future__ import annotations -import numbers import ssl from typing import Any, Callable, Dict, Mapping, Optional, Union, Type @@ -17,7 +16,7 @@ from . import ( PRODUCT: str -_OnHeartbeatTimeoutCallback = Callable[['Connection', numbers.Integral], int] +_OnHeartbeatTimeoutCallback = Callable[['Connection', int], int] _OnCloseCallback = Callable[['Connection', Exception], None] _OnConnectionBlockedCallback = Callable[ ['Connection', frame.Method[spec.Connection.Blocked]], @@ -40,19 +39,19 @@ class Parameters: DEFAULT_USERNAME: str = ... DEFAULT_PASSWORD: str = ... - DEFAULT_BLOCKED_CONNECTION_TIMEOUT: Optional[numbers.Real] = ... + DEFAULT_BLOCKED_CONNECTION_TIMEOUT: Optional[float | int] = ... DEFAULT_CHANNEL_MAX: int = ... DEFAULT_CLIENT_PROPERTIES: Optional[Mapping[str, Any]] = ... DEFAULT_CREDENTIALS: credentials_._VALID_TYPES = ... DEFAULT_CONNECTION_ATTEMPTS: Literal[1] = ... DEFAULT_FRAME_MAX: int = ... - DEFAULT_HEARTBEAT_TIMEOUT: Optional[Union[numbers.Integral, _OnHeartbeatTimeoutCallback]] = ... + DEFAULT_HEARTBEAT_TIMEOUT: Optional[Union[int, _OnHeartbeatTimeoutCallback]] = ... DEFAULT_HOST: str = ... DEFAULT_LOCALE: str = ... DEFAULT_PORT: int = ... - DEFAULT_RETRY_DELAY: numbers.Real = ... - DEFAULT_SOCKET_TIMEOUT: numbers.Real = ... - DEFAULT_STACK_TIMEOUT: numbers.Real = ... + DEFAULT_RETRY_DELAY: float | int = ... + DEFAULT_SOCKET_TIMEOUT: float | int = ... + DEFAULT_STACK_TIMEOUT: float | int = ... DEFAULT_SSL: bool = ... DEFAULT_SSL_OPTIONS: Optional[SSLOptions] = ... DEFAULT_SSL_PORT: int = ... @@ -60,36 +59,36 @@ class Parameters: DEFAULT_TCP_OPTIONS: Optional[Mapping[str, Any]] = ... @property - def blocked_connection_timeout(self) -> numbers.Real: ... + def blocked_connection_timeout(self) -> float | int: ... @blocked_connection_timeout.setter - def blocked_connection_timeout(self, value: Optional[numbers.Real]) -> None: ... + def blocked_connection_timeout(self, value: Optional[float | int]) -> None: ... @property - def channel_max(self) -> numbers.Integral: ... + def channel_max(self) -> int: ... @channel_max.setter - def channel_max(self, value: numbers.Integral) -> None: ... + def channel_max(self, value: int) -> None: ... @property def client_properties(self) -> Optional[Mapping[str, Any]]: ... @client_properties.setter def client_properties(self, value: Optional[Mapping[str, Any]]) -> None: ... @property - def connection_attempts(self) -> numbers.Integral: ... + def connection_attempts(self) -> int: ... @connection_attempts.setter - def connection_attempts(self, value: numbers.Integral) -> None: ... + def connection_attempts(self, value: int) -> None: ... @property def credentials(self) -> credentials_._VALID_TYPES: ... @credentials.setter def credentials(self, value: credentials_._VALID_TYPES) -> None: ... @property - def frame_max(self) -> numbers.Integral: ... + def frame_max(self) -> int: ... @frame_max.setter - def frame_max(self, value: numbers.Integral) -> None: ... + def frame_max(self, value: int) -> None: ... @property - def heartbeat(self) -> Optional[Union[numbers.Integral, _OnHeartbeatTimeoutCallback]]: ... + def heartbeat(self) -> Optional[Union[int, _OnHeartbeatTimeoutCallback]]: ... @heartbeat.setter def heartbeat( self, - value: Optional[Union[numbers.Integral, _OnHeartbeatTimeoutCallback]], + value: Optional[Union[int, _OnHeartbeatTimeoutCallback]], ) -> None: ... @property @@ -105,17 +104,17 @@ class Parameters: @port.setter def port(self, value: int) -> None: ... @property - def retry_delay(self) -> numbers.Real: ... + def retry_delay(self) -> float | int: ... @retry_delay.setter - def retry_delay(self, value: numbers.Real) -> None: ... + def retry_delay(self, value: float | int) -> None: ... @property - def socket_timeout(self) -> Optional[numbers.Real]: ... + def socket_timeout(self) -> Optional[float | int]: ... @socket_timeout.setter - def socket_timeout(self, value: Optional[numbers.Real]) -> None: ... + def socket_timeout(self, value: Optional[float | int]) -> None: ... @property - def stack_timeout(self) -> Optional[numbers.Real]: ... + def stack_timeout(self) -> Optional[float | int]: ... @stack_timeout.setter - def stack_timeout(self, value: Optional[numbers.Real]) -> None: ... + def stack_timeout(self, value: Optional[float | int]) -> None: ... @property def ssl_options(self) -> Optional[SSLOptions]: ... @ssl_options.setter @@ -142,11 +141,11 @@ class ConnectionParameters(Parameters): heartbeat: Union[int, _OnHeartbeatTimeoutCallback, None, Type[_DEFAULT]] = ..., ssl_options: Union[SSLOptions, Type[_DEFAULT]] = ..., connection_attempts: Union[int, Type[_DEFAULT]] = ..., - retry_delay: Union[numbers.Real, Type[_DEFAULT]] = ..., - socket_timeout: Union[numbers.Real, Type[_DEFAULT]] = ..., - stack_timeout: Union[numbers.Real, Type[_DEFAULT]] = ..., + retry_delay: Union[float | int, Type[_DEFAULT]] = ..., + socket_timeout: Union[float | int, Type[_DEFAULT]] = ..., + stack_timeout: Union[float | int, Type[_DEFAULT]] = ..., locale: Union[str, Type[_DEFAULT]] = ..., - blocked_connection_timeout: Union[numbers.Real, None, Type[_DEFAULT]] = ..., + blocked_connection_timeout: Union[float | int, None, Type[_DEFAULT]] = ..., client_properties: Union[Mapping[str, Any], None, Type[_DEFAULT]] = ..., tcp_options: Union[Mapping[str, Any], None, Type[_DEFAULT]] = ..., **kwargs: Any, diff --git a/setup.cfg b/setup.cfg index 0c5890b..ea75718 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,7 +27,7 @@ install_requires = dev = flake8~=4.0.0 flake8-pyi - mypy~=0.900 + mypy~=0.920 pika==1.2.0 tornado twisted From 605eaa928c268cd9e1c36c90dfba2f684129aaff Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Mon, 17 Jan 2022 14:45:22 -0600 Subject: [PATCH 06/11] use PEP 604 union syntax --- pika-stubs/adapters/asyncio_connection.pyi | 26 +- pika-stubs/adapters/base_connection.pyi | 24 +- pika-stubs/adapters/blocking_connection.pyi | 86 +++--- pika-stubs/adapters/select_connection.pyi | 33 +-- pika-stubs/adapters/tornado_connection.pyi | 31 +-- pika-stubs/adapters/twisted_connection.pyi | 52 ++-- .../adapters/utils/connection_workflow.pyi | 18 +- .../adapters/utils/io_services_utils.pyi | 17 +- pika-stubs/adapters/utils/nbio_interface.pyi | 22 +- .../utils/selector_ioloop_adapter.pyi | 12 +- pika-stubs/amqp_object.pyi | 4 +- pika-stubs/callback.pyi | 14 +- pika-stubs/channel.pyi | 72 ++--- pika-stubs/connection.pyi | 128 ++++----- pika-stubs/credentials.pyi | 8 +- pika-stubs/frame.pyi | 10 +- pika-stubs/spec.pyi | 250 +++++++++--------- 17 files changed, 367 insertions(+), 440 deletions(-) diff --git a/pika-stubs/adapters/asyncio_connection.pyi b/pika-stubs/adapters/asyncio_connection.pyi index fd8c03e..9e83c0d 100644 --- a/pika-stubs/adapters/asyncio_connection.pyi +++ b/pika-stubs/adapters/asyncio_connection.pyi @@ -1,5 +1,5 @@ import asyncio -from typing import Callable, Optional, Sequence, Union +from typing import Callable, Sequence from .. import connection from . import base_connection @@ -7,18 +7,18 @@ from .utils import connection_workflow _OnCloseCallback = Callable[['AsyncioConnection', Exception], None] _OnOpenCallback = Callable[['AsyncioConnection'], None] -_OnOpenErrorCallback = Callable[['AsyncioConnection', Union[str, Exception]], None] +_OnOpenErrorCallback = Callable[['AsyncioConnection', str | Exception], None] class AsyncioConnection(base_connection.BaseConnection[asyncio.AbstractEventLoop]): def __init__( self, - parameters: Optional[connection.Parameters] = ..., - on_open_callback: Optional[_OnOpenCallback] = ..., - on_open_error_callback: Optional[_OnOpenErrorCallback] = ..., - on_close_callback: Optional[_OnCloseCallback] = ..., - custom_ioloop: Optional[asyncio.AbstractEventLoop] = ..., + parameters: connection.Parameters | None = ..., + on_open_callback: _OnOpenCallback | None = ..., + on_open_error_callback: _OnOpenErrorCallback | None = ..., + on_close_callback: _OnCloseCallback | None = ..., + custom_ioloop: asyncio.AbstractEventLoop | None = ..., internal_connection_workflow: bool = ..., ) -> None: ... @@ -28,14 +28,12 @@ class AsyncioConnection(base_connection.BaseConnection[asyncio.AbstractEventLoop connection_configs: Sequence[connection.Parameters], on_done: Callable[ [ - Union[ - connection.Connection, - connection_workflow.AMQPConnectionWorkflowFailed, - connection_workflow.AMQPConnectionWorkflowAborted, - ], + connection.Connection | + connection_workflow.AMQPConnectionWorkflowFailed | + connection_workflow.AMQPConnectionWorkflowAborted ], None ], - custom_ioloop: Optional[asyncio.AbstractEventLoop] = ..., - workflow: Optional[connection_workflow.AbstractAMQPConnectionWorkflow] = ..., + custom_ioloop: asyncio.AbstractEventLoop | None = ..., + workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = ..., ) -> connection_workflow.AbstractAMQPConnectionWorkflow: ... diff --git a/pika-stubs/adapters/base_connection.pyi b/pika-stubs/adapters/base_connection.pyi index 7fc423e..7774698 100644 --- a/pika-stubs/adapters/base_connection.pyi +++ b/pika-stubs/adapters/base_connection.pyi @@ -1,12 +1,12 @@ import abc -from typing import Callable, Generic, Optional, Sequence, TypeVar, Union +from typing import Callable, Generic, Sequence, TypeVar from .. import connection from .utils import connection_workflow, nbio_interface _OnCloseCallback = Callable[['BaseConnection', Exception], None] _OnOpenCallback = Callable[['BaseConnection'], None] -_OnOpenErrorCallback = Callable[['BaseConnection', Union[str, Exception]], None] +_OnOpenErrorCallback = Callable[['BaseConnection', str | Exception], None] _IOLoop = TypeVar('_IOLoop') @@ -15,10 +15,10 @@ class BaseConnection(Generic[_IOLoop], connection.Connection): def __init__( self, - parameters: Optional[connection.Parameters], - on_open_callback: Optional[_OnOpenCallback], - on_open_error_callback: Optional[_OnOpenErrorCallback], - on_close_callback: Optional[_OnCloseCallback], + parameters: connection.Parameters | None, + on_open_callback: _OnOpenCallback | None, + on_open_error_callback: _OnOpenErrorCallback | None, + on_close_callback: _OnCloseCallback | None, nbio: nbio_interface.AbstractIOServices, internal_connection_workflow: bool, ) -> None: ... @@ -30,16 +30,14 @@ class BaseConnection(Generic[_IOLoop], connection.Connection): connection_configs: Sequence[connection.Parameters], on_done: Callable[ [ - Union[ - connection.Connection, - connection_workflow.AMQPConnectionWorkflowFailed, - connection_workflow.AMQPConnectionWorkflowAborted, - ], + connection.Connection | + connection_workflow.AMQPConnectionWorkflowFailed | + connection_workflow.AMQPConnectionWorkflowAborted, ], None ], - custom_ioloop: Optional[_IOLoop] = ..., - workflow: Optional[connection_workflow.AbstractAMQPConnectionWorkflow] = ..., + custom_ioloop: _IOLoop | None = ..., + workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = ..., ) -> connection_workflow.AbstractAMQPConnectionWorkflow: ... @property diff --git a/pika-stubs/adapters/blocking_connection.pyi b/pika-stubs/adapters/blocking_connection.pyi index c1a2ba4..e8f647e 100644 --- a/pika-stubs/adapters/blocking_connection.pyi +++ b/pika-stubs/adapters/blocking_connection.pyi @@ -1,7 +1,7 @@ from __future__ import annotations import types -from typing import Any, Callable, Iterator, List, Mapping, Optional, Tuple, Type, Union, Sequence +from typing import Any, Callable, Iterator, List, Mapping, Tuple, Type, Sequence from .. import channel, connection, frame, spec from ..exchange_type import ExchangeType @@ -12,16 +12,16 @@ class BlockingConnection: def __init__( self, parameters: connection.Parameters | Sequence[connection.Parameters] | None = ..., - _impl_class: Optional[Any] = ..., + _impl_class: Any | None = ..., ) -> None: ... def __enter__(self) -> BlockingConnection: ... def __exit__( self, - exc_type: Optional[Type[BaseException]], - value: Optional[BaseException], - traceback: Optional[types.TracebackType], + exc_type: Type[BaseException] | None, + value: BaseException | None, + traceback: types.TracebackType | None, ) -> None: ... def add_on_connection_blocked_callback( @@ -45,7 +45,7 @@ class BlockingConnection: def close(self, reply_code: int = ..., reply_text: str = ...) -> None: ... def process_data_events(self, time_limit: int = ...) -> None: ... def sleep(self, duration: float) -> None: ... - def channel(self, channel_number: Optional[int] = ...) -> BlockingChannel: ... + def channel(self, channel_number: int | None = ...) -> BlockingChannel: ... @property def is_closed(self) -> bool: ... @@ -95,9 +95,9 @@ class BlockingChannel: def __exit__( self, - exc_type: Optional[Type[BaseException]], - value: Optional[BaseException], - traceback: Optional[types.TracebackType], + exc_type: Type[BaseException] | None, + value: BaseException | None, + traceback: types.TracebackType | None, ) -> None: ... @property @@ -131,36 +131,34 @@ class BlockingChannel: ], auto_ack: bool = ..., exclusive: bool = ..., - consumer_tag: Optional[str] = ..., - arguments: Optional[Mapping[str, Any]] = ..., + consumer_tag: str | None = ..., + arguments: Mapping[str, Any] | None = ..., ) -> str: ... def basic_cancel(self, consumer_tag: str) -> List[ Tuple[spec.Basic.Deliver, spec.BasicProperties, bytes], ]: ... def start_consuming(self) -> None: ... - def stop_consuming(self, consumer_tag: Optional[str] = ...) -> None: ... + def stop_consuming(self, consumer_tag: str | None = ...) -> None: ... def consume( self, queue: str, auto_ack: bool = ..., exclusive: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., - inactivity_timeout: Optional[float] = ..., + arguments: Mapping[str, Any] | None = ..., + inactivity_timeout: float | None = ..., ) -> Iterator[ - Union[ - Tuple[ - spec.Basic.Deliver, - spec.BasicProperties, - bytes, - ], - Tuple[ - None, - None, - None, - ], - ] + Tuple[ + spec.Basic.Deliver, + spec.BasicProperties, + bytes, + ] | + Tuple[ + None, + None, + None, + ], ]: ... def get_waiting_message_count(self) -> int: ... @@ -171,15 +169,15 @@ class BlockingChannel: def basic_nack( self, - delivery_tag: Optional[int] = ..., + delivery_tag: int | None = ..., multiple: bool = ..., requeue: bool = ..., ) -> None: ... def basic_get(self, queue: str, auto_ack: bool = ...) -> Tuple[ - Optional[spec.Basic.GetOk], - Optional[spec.BasicProperties], - Optional[str], + spec.Basic.GetOk | None, + spec.BasicProperties | None, + str | None, ]: ... def basic_publish( @@ -187,7 +185,7 @@ class BlockingChannel: exchange: str, routing_key: str, body: bytes | str, - properties: Optional[spec.BasicProperties] = ..., + properties: spec.BasicProperties | None = ..., mandatory: bool = ..., ) -> None: ... @@ -199,7 +197,7 @@ class BlockingChannel: ) -> None: ... def basic_recover(self, requeue: bool = ...) -> None: ... - def basic_reject(self, delivery_tag: Optional[int] = ..., requeue: bool = ...) -> None: ... + def basic_reject(self, delivery_tag: int | None = ..., requeue: bool = ...) -> None: ... def confirm_delivery(self) -> None: ... @@ -211,12 +209,12 @@ class BlockingChannel: durable: bool = ..., auto_delete: bool = ..., internal: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> frame.Method[spec.Exchange.DeclareOk]: ... def exchange_delete( self, - exchange: Optional[str] = ..., + exchange: str | None = ..., if_unused: bool = ..., ) -> frame.Method[spec.Exchange.DeleteOk]: ... @@ -225,15 +223,15 @@ class BlockingChannel: destination: str, source: str, routing_key: str = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> frame.Method[spec.Exchange.BindOk]: ... def exchange_unbind( self, - destination: Optional[str] = ..., - source: Optional[str] = ..., + destination: str | None = ..., + source: str | None = ..., routing_key: str = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> frame.Method[spec.Exchange.UnbindOk]: ... def queue_declare( @@ -243,7 +241,7 @@ class BlockingChannel: durable: bool = ..., exclusive: bool = ..., auto_delete: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> frame.Method[spec.Queue.DeclareOk]: ... def queue_delete( @@ -259,16 +257,16 @@ class BlockingChannel: self, queue: str, exchange: str, - routing_key: Optional[str] = ..., - arguments: Optional[Mapping[str, Any]] = ..., + routing_key: str | None = ..., + arguments: Mapping[str, Any] | None = ..., ) -> frame.Method[spec.Queue.BindOk]: ... def queue_unbind( self, queue: Any, - exchange: Optional[str] = ..., - routing_key: Optional[str] = ..., - arguments: Optional[Mapping[str, Any]] = ..., + exchange: str | None = ..., + routing_key: str | None = ..., + arguments: Mapping[str, Any] | None = ..., ) -> frame.Method[spec.Queue.UnbindOk]: ... def tx_select(self) -> frame.Method[spec.Tx.SelectOk]: ... diff --git a/pika-stubs/adapters/select_connection.pyi b/pika-stubs/adapters/select_connection.pyi index 3418a59..b73765c 100644 --- a/pika-stubs/adapters/select_connection.pyi +++ b/pika-stubs/adapters/select_connection.pyi @@ -1,33 +1,28 @@ from __future__ import annotations import abc -from typing import Any, AnyStr, Callable, IO, Optional, Sequence, Union +from typing import Any, AnyStr, Callable, IO, Sequence from .. import compat, connection from . import base_connection from .utils import connection_workflow, nbio_interface, selector_ioloop_adapter -SELECT_TYPE: Optional[str] +SELECT_TYPE: str | None _OnCloseCallback = Callable[[base_connection.BaseConnection, Exception], None] _OnOpenCallback = Callable[[base_connection.BaseConnection], None] -_OnOpenErrorCallback = Callable[[base_connection.BaseConnection, Union[str, Exception]], None] +_OnOpenErrorCallback = Callable[[base_connection.BaseConnection, str | Exception], None] class SelectConnection(base_connection.BaseConnection['IOLoop']): def __init__( self, - parameters: Optional[connection.Parameters] = ..., - on_open_callback: Optional[_OnOpenCallback] = ..., - on_open_error_callback: Optional[_OnOpenErrorCallback] = ..., - on_close_callback: Optional[_OnCloseCallback] = ..., - custom_ioloop: Optional[ - Union[ - IOLoop, - nbio_interface.AbstractIOServices, - ], - ] = ..., + parameters: connection.Parameters | None = ..., + on_open_callback: _OnOpenCallback | None = ..., + on_open_error_callback: _OnOpenErrorCallback | None = ..., + on_close_callback: _OnCloseCallback | None = ..., + custom_ioloop: IOLoop | nbio_interface.AbstractIOServices | None = ..., internal_connection_workflow: bool = ..., ) -> None: ... @@ -37,16 +32,14 @@ class SelectConnection(base_connection.BaseConnection['IOLoop']): connection_configs: Sequence[connection.Parameters], on_done: Callable[ [ - Union[ - connection.Connection, - connection_workflow.AMQPConnectionWorkflowFailed, - connection_workflow.AMQPConnectionWorkflowAborted, - ], + connection.Connection | + connection_workflow.AMQPConnectionWorkflowFailed | + connection_workflow.AMQPConnectionWorkflowAborted ], None ], - custom_ioloop: Optional[IOLoop] = ..., - workflow: Optional[connection_workflow.AbstractAMQPConnectionWorkflow] = ..., + custom_ioloop: IOLoop | None = ..., + workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = ..., ) -> connection_workflow.AbstractAMQPConnectionWorkflow: ... diff --git a/pika-stubs/adapters/tornado_connection.pyi b/pika-stubs/adapters/tornado_connection.pyi index 579f76d..8c3e94b 100644 --- a/pika-stubs/adapters/tornado_connection.pyi +++ b/pika-stubs/adapters/tornado_connection.pyi @@ -1,4 +1,4 @@ -from typing import Callable, Optional, Sequence, Union +from typing import Callable, Sequence import tornado.ioloop @@ -8,23 +8,18 @@ from .utils import connection_workflow, nbio_interface _OnCloseCallback = Callable[['TornadoConnection', Exception], None] _OnOpenCallback = Callable[['TornadoConnection'], None] -_OnOpenErrorCallback = Callable[['TornadoConnection', Union[str, Exception]], None] +_OnOpenErrorCallback = Callable[['TornadoConnection', str | Exception], None] class TornadoConnection(base_connection.BaseConnection[tornado.ioloop.IOLoop]): def __init__( self, - parameters: Optional[connection.Parameters] = ..., - on_open_callback: Optional[_OnOpenCallback] = ..., - on_open_error_callback: Optional[_OnOpenErrorCallback] = ..., - on_close_callback: Optional[_OnCloseCallback] = ..., - custom_ioloop: Optional[ - Union[ - tornado.ioloop.IOLoop, - nbio_interface.AbstractIOServices, - ], - ] = ..., + parameters: connection.Parameters | None = ..., + on_open_callback: _OnOpenCallback | None = ..., + on_open_error_callback: _OnOpenErrorCallback | None = ..., + on_close_callback: _OnCloseCallback | None = ..., + custom_ioloop: tornado.ioloop.IOLoop | nbio_interface.AbstractIOServices | None = ..., internal_connection_workflow: bool = ..., ) -> None: ... @@ -34,14 +29,12 @@ class TornadoConnection(base_connection.BaseConnection[tornado.ioloop.IOLoop]): connection_configs: Sequence[connection.Parameters], on_done: Callable[ [ - Union[ - connection.Connection, - connection_workflow.AMQPConnectionWorkflowFailed, - connection_workflow.AMQPConnectionWorkflowAborted, - ], + connection.Connection | + connection_workflow.AMQPConnectionWorkflowFailed | + connection_workflow.AMQPConnectionWorkflowAborted ], None ], - custom_ioloop: Optional[tornado.ioloop.IOLoop] = ..., - workflow: Optional[connection_workflow.AbstractAMQPConnectionWorkflow] = ..., + custom_ioloop: tornado.ioloop.IOLoop | None = ..., + workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = ..., ) -> connection_workflow.AbstractAMQPConnectionWorkflow: ... diff --git a/pika-stubs/adapters/twisted_connection.pyi b/pika-stubs/adapters/twisted_connection.pyi index 9d1fe19..e679716 100644 --- a/pika-stubs/adapters/twisted_connection.pyi +++ b/pika-stubs/adapters/twisted_connection.pyi @@ -6,9 +6,7 @@ from typing import ( List, Mapping, NamedTuple, - Optional, Sequence, - Union, TypeVar, Tuple, ) @@ -32,17 +30,17 @@ _T = TypeVar("_T") class ClosableDeferredQueue(DeferredQueue[_T]): - closed: Union[twisted.python.failure.Failure, Exception] = ... + closed: twisted.python.failure.Failure | Exception = ... def __init__( self, - size: Optional[int] = ..., - backlog: Optional[int] = ..., + size: int | None = ..., + backlog: int | None = ..., ) -> None: ... def put(self, obj: _T) -> None: ... def get(self) -> Deferred[_T]: ... - def close(self, reason: Union[twisted.python.failure.Failure, Exception, str]) -> None: ... + def close(self, reason: twisted.python.failure.Failure | Exception | str) -> None: ... # Generic [named] tuples aren't supported (https://github.com/python/mypy/issues/685) @@ -55,7 +53,7 @@ class ReceivedMessage(NamedTuple): class TwistedChannel: - on_closed: Deferred[Union[twisted.python.failure.Failure, Exception, str]] + on_closed: Deferred[twisted.python.failure.Failure | Exception | str] def __init__(self, channel: Channel) -> None: ... @@ -93,8 +91,8 @@ class TwistedChannel: queue: str, auto_ack: bool = ..., exclusive: bool = ..., - consumer_tag: Optional[str] = ..., - arguments: Optional[Mapping[str, Any]] = ..., + consumer_tag: str | None = ..., + arguments: Mapping[str, Any] | None = ..., ) -> Deferred[Tuple[ClosableDeferredQueue[ReceivedMessage], str]]: ... # ReceivedMessage.method: spec.Basic.GetOk @@ -106,7 +104,7 @@ class TwistedChannel: def basic_nack( self, - delivery_tag: Optional[int] = ..., + delivery_tag: int | None = ..., multiple: bool = ..., requeue: bool = ..., ) -> None: ... @@ -116,7 +114,7 @@ class TwistedChannel: exchange: str, routing_key: str, body: bytes | str, - properties: Optional[spec.BasicProperties] = ..., + properties: spec.BasicProperties | None = ..., mandatory: bool = ..., ) -> Deferred[None]: ... @@ -140,7 +138,7 @@ class TwistedChannel: destination: str, source: str, routing_key: str = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> Deferred[frame.Method[spec.Exchange.BindOk]]: ... def exchange_declare( @@ -151,21 +149,21 @@ class TwistedChannel: durable: bool = ..., auto_delete: bool = ..., internal: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> Deferred[frame.Method[spec.Exchange.DeclareOk]]: ... def exchange_delete( self, - exchange: Optional[str] = ..., + exchange: str | None = ..., if_unused: bool = ..., ) -> Deferred[frame.Method[spec.Exchange.DeleteOk]]: ... def exchange_unbind( self, - destination: Optional[str] = ..., - source: Optional[str] = ..., + destination: str | None = ..., + source: str | None = ..., routing_key: str = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> Deferred[frame.Method[spec.Exchange.UnbindOk]]: ... def flow(self, active: bool) -> Deferred[frame.Method[spec.Channel.FlowOk]]: ... @@ -175,8 +173,8 @@ class TwistedChannel: self, queue: str, exchange: str, - routing_key: Optional[str] = ..., - arguments: Optional[Mapping[str, Any]] = ..., + routing_key: str | None = ..., + arguments: Mapping[str, Any] | None = ..., ) -> Deferred[frame.Method[spec.Queue.BindOk]]: ... def queue_declare( @@ -186,7 +184,7 @@ class TwistedChannel: durable: bool = ..., exclusive: bool = ..., auto_delete: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> Deferred[frame.Method[spec.Queue.DeclareOk]]: ... def queue_delete( @@ -201,9 +199,9 @@ class TwistedChannel: def queue_unbind( self, queue: str, - exchange: Optional[str] = ..., - routing_key: Optional[str] = ..., - arguments: Optional[Mapping[str, Any]] = ..., + exchange: str | None = ..., + routing_key: str | None = ..., + arguments: Mapping[str, Any] | None = ..., ) -> Deferred[frame.Method[spec.Queue.UnbindOk]]: ... def tx_commit(self) -> Deferred[frame.Method[spec.Tx.CommitOk]]: ... @@ -214,15 +212,15 @@ class TwistedChannel: class TwistedProtocolConnection(twisted.internet.protocol.Protocol): ready: Deferred[TwistedProtocolConnection] = ... - closed: Optional[Deferred[Union[twisted.python.failure.Failure, Exception]]] = ... + closed: Deferred[twisted.python.failure.Failure | Exception] | None = ... def __init__( self, - parameters: Optional[Parameters] = ..., - custom_reactor: Optional[twisted.internet.base.ReactorBase] = ..., + parameters: Parameters | None = ..., + custom_reactor: twisted.internet.base.ReactorBase | None = ..., ) -> None: ... - def channel(self, channel_number: Optional[int] = ...) -> Deferred[TwistedChannel]: ... + def channel(self, channel_number: int | None = ...) -> Deferred[TwistedChannel]: ... @property def is_open(self) -> bool: ... diff --git a/pika-stubs/adapters/utils/connection_workflow.pyi b/pika-stubs/adapters/utils/connection_workflow.pyi index 061e01f..726ad5b 100644 --- a/pika-stubs/adapters/utils/connection_workflow.pyi +++ b/pika-stubs/adapters/utils/connection_workflow.pyi @@ -1,4 +1,4 @@ -from typing import Any, Callable, Union +from typing import Any, Callable from ... import compat, connection from . import nbio_interface @@ -70,11 +70,9 @@ class AbstractAMQPConnectionWorkflow(compat.AbstractBase): native_loop: object, on_done: Callable[ [ - Union[ - connection.Connection, - AMQPConnectionWorkflowFailed, - AMQPConnectionWorkflowAborted, - ], + connection.Connection | + AMQPConnectionWorkflowFailed| + AMQPConnectionWorkflowAborted ], None ], @@ -96,11 +94,9 @@ class AMQPConnectionWorkflow(AbstractAMQPConnectionWorkflow): native_loop: object, on_done: Callable[ [ - Union[ - connection.Connection, - AMQPConnectionWorkflowFailed, - AMQPConnectionWorkflowAborted, - ], + connection.Connection | + AMQPConnectionWorkflowFailed | + AMQPConnectionWorkflowAborted ], None ], diff --git a/pika-stubs/adapters/utils/io_services_utils.pyi b/pika-stubs/adapters/utils/io_services_utils.pyi index 1ba0d1b..06f45b3 100644 --- a/pika-stubs/adapters/utils/io_services_utils.pyi +++ b/pika-stubs/adapters/utils/io_services_utils.pyi @@ -2,7 +2,7 @@ from __future__ import annotations import ssl from socket import socket -from typing import Any, Callable, Optional, Tuple, Union +from typing import Any, Callable, Tuple from . import nbio_interface @@ -15,7 +15,7 @@ class SocketConnectionMixin: self, sock: socket, resolved_addr: Any, - on_done: Callable[[Optional[BaseException]], None], + on_done: Callable[[BaseException | None], None], ) -> nbio_interface.AbstractIOReference: ... @@ -25,18 +25,7 @@ class StreamingConnectionMixin: self, protocol_factory: Callable[[], nbio_interface.AbstractStreamProtocol], sock: socket, - on_done: Callable[ - [ - Union[ - BaseException, - Tuple[ - nbio_interface.AbstractStreamTransport, - nbio_interface.AbstractStreamProtocol, - ], - ] - ], - None, - ], + on_done: Callable[[ BaseException | Tuple[ nbio_interface.AbstractStreamTransport, nbio_interface.AbstractStreamProtocol]], None], ssl_context: ssl.SSLContext | None = ..., server_hostname: str | None = ..., ) -> nbio_interface.AbstractIOReference: ... diff --git a/pika-stubs/adapters/utils/nbio_interface.pyi b/pika-stubs/adapters/utils/nbio_interface.pyi index 5be595e..8587bba 100644 --- a/pika-stubs/adapters/utils/nbio_interface.pyi +++ b/pika-stubs/adapters/utils/nbio_interface.pyi @@ -3,7 +3,7 @@ from __future__ import annotations import abc import ssl from socket import AddressFamily, SocketKind, socket -from typing import Any, AnyStr, Callable, IO, List, Optional, Text, Tuple, Union +from typing import Any, AnyStr, Callable, IO, List, Text, Tuple from ... import compat @@ -25,14 +25,12 @@ class AbstractIOServices(compat.AbstractBase): @abc.abstractmethod def getaddrinfo( self, - host: Optional[Union[bytearray, bytes, Text]], - port: Union[str, int, None], + host: bytearray | bytes | Text | None, + port: str | int | None, on_done: Callable[ [ - Union[ - BaseException, - List[Tuple[AddressFamily, SocketKind, int, str, Tuple[Any, ...]]], - ] + BaseException | + List[Tuple[AddressFamily, SocketKind, int, str, Tuple[Any, ...]]], ], None, ], @@ -47,7 +45,7 @@ class AbstractIOServices(compat.AbstractBase): self, sock: socket, resolved_addr: Any, - on_done: Callable[[Optional[BaseException]], None], + on_done: Callable[[BaseException | None], None], ) -> AbstractIOReference: ... @abc.abstractmethod @@ -57,10 +55,8 @@ class AbstractIOServices(compat.AbstractBase): sock: socket, on_done: Callable[ [ - Union[ - BaseException, - Tuple[AbstractStreamTransport, AbstractStreamProtocol], - ] + BaseException | + Tuple[AbstractStreamTransport, AbstractStreamProtocol], ], None, ], @@ -98,7 +94,7 @@ class AbstractStreamProtocol(compat.AbstractBase): @abc.abstractmethod def connection_made(self, transport: AbstractStreamTransport) -> None: ... @abc.abstractmethod - def connection_lost(self, error: Optional[BaseException]) -> None: ... + def connection_lost(self, error: BaseException | None) -> None: ... @abc.abstractmethod def eof_received(self) -> Any: ... @abc.abstractmethod diff --git a/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi b/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi index e2bc0e6..702cd5f 100644 --- a/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi +++ b/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi @@ -7,11 +7,9 @@ from typing import ( Generic, IO, List, - Optional, Text, Tuple, TypeVar, - Union, ) from . import io_services_utils, nbio_interface @@ -81,14 +79,12 @@ class SelectorIOServicesAdapter( def getaddrinfo( self, - host: Optional[Union[bytearray, bytes, Text]], - port: Union[str, int, None], + host: bytearray | bytes | Text | None, + port: str | int | None, on_done: Callable[ [ - Union[ - BaseException, - List[Tuple[AddressFamily, SocketKind, int, str, Tuple[Any, ...]]], - ] + BaseException | + List[Tuple[AddressFamily, SocketKind, int, str, Tuple[Any, ...]]], ], None, ], diff --git a/pika-stubs/amqp_object.pyi b/pika-stubs/amqp_object.pyi index e95944c..d59735d 100644 --- a/pika-stubs/amqp_object.pyi +++ b/pika-stubs/amqp_object.pyi @@ -1,12 +1,10 @@ from __future__ import annotations -from typing import Optional - class AMQPObject: NAME: str = ... - INDEX: Optional[int] = ... + INDEX: int | None = ... class Class(AMQPObject): diff --git a/pika-stubs/callback.pyi b/pika-stubs/callback.pyi index 5a0df78..0e41e0e 100644 --- a/pika-stubs/callback.pyi +++ b/pika-stubs/callback.pyi @@ -1,8 +1,8 @@ -from typing import Any, Callable, Mapping, Optional, Tuple, Union +from typing import Any, Callable, Mapping, Tuple from . import amqp_object -_Prefix = Union[int, str] +_Prefix = int | str _Key = Any _Caller = object _Callback = Callable[..., Any] @@ -28,14 +28,14 @@ class CallbackManager: key: _Key, callback: _Callback, one_shot: bool = ..., - only_caller: Optional[_Caller] = ..., - arguments: Optional[Mapping[str, Any]] = ..., + only_caller: _Caller | None = ..., + arguments: Mapping[str, Any] | None = ..., ) -> Tuple[_Prefix, Any]: ... def clear(self) -> None: ... def cleanup(self, prefix: _Prefix) -> bool: ... - def pending(self, prefix: _Prefix, key: _Key) -> Optional[int]: ... + def pending(self, prefix: _Prefix, key: _Key) -> int | None: ... def process( self, @@ -50,7 +50,7 @@ class CallbackManager: self, prefix: _Prefix, key: _Key, - callback_value: Optional[_Callback] = ..., - arguments: Optional[Mapping[str, Any]] = ..., + callback_value: _Callback | None = ..., + arguments: Mapping[str, Any] | None = ..., ) -> bool: ... def remove_all(self, prefix: _Prefix, key: _Key) -> None: ... diff --git a/pika-stubs/channel.pyi b/pika-stubs/channel.pyi index b945b56..7a5b41e 100644 --- a/pika-stubs/channel.pyi +++ b/pika-stubs/channel.pyi @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, Callable, List, Mapping, Optional, Sequence, Tuple, Union +from typing import Any, Callable, List, Mapping, Sequence, Tuple from typing_extensions import Literal @@ -14,7 +14,7 @@ from .exchange_type import ExchangeType MAX_CHANNELS: Literal[65535] # per AMQP 0.9.1 spec. -_OnAckNackCallback = Callable[[frame.Method[Union[spec.Basic.Ack, spec.Basic.Nack]]], None] +_OnAckNackCallback = Callable[[frame.Method[spec.Basic.Ack | spec.Basic.Nack]], None] _OnConfirmDeliveryCallback = Callable[[frame.Method[spec.Confirm.SelectOk]], None] _OnBasicConsumeCallback = Callable[[frame.Method[spec.Basic.ConsumeOk]], None] _OnBasicGetCallback = Callable[['Channel', spec.Basic.GetOk, spec.BasicProperties, bytes], None] @@ -81,7 +81,7 @@ class Channel: def basic_cancel( self, consumer_tag: str = ..., - callback: Optional[_OnBasicCancelCallback] = ..., + callback: _OnBasicCancelCallback | None = ..., ) -> None: ... def basic_consume( @@ -90,9 +90,9 @@ class Channel: on_message_callback: _OnMessageCallback, auto_ack: bool = ..., exclusive: bool = ..., - consumer_tag: Optional[str] = ..., - arguments: Optional[Mapping[str, Any]] = ..., - callback: Optional[_OnBasicConsumeCallback] = ..., + consumer_tag: str | None = ..., + arguments: Mapping[str, Any] | None = ..., + callback: _OnBasicConsumeCallback | None = ..., ) -> str: ... def basic_get( @@ -104,7 +104,7 @@ class Channel: def basic_nack( self, - delivery_tag: Optional[int] = ..., + delivery_tag: int | None = ..., multiple: bool = ..., requeue: bool = ..., ) -> None: ... @@ -114,7 +114,7 @@ class Channel: exchange: str, routing_key: str, body: bytes | str, - properties: Optional[spec.BasicProperties] = ..., + properties: spec.BasicProperties | None = ..., mandatory: bool = ..., ) -> None: ... @@ -123,7 +123,7 @@ class Channel: prefetch_size: int = ..., prefetch_count: int = ..., global_qos: bool = ..., - callback: Optional[_OnBasicQosCallback] = ..., + callback: _OnBasicQosCallback | None = ..., ) -> None: ... def basic_reject(self, delivery_tag: int = ..., requeue: bool = ...) -> None: ... @@ -131,7 +131,7 @@ class Channel: def basic_recover( self, requeue: bool = ..., - callback: Optional[_OnBasicRecoverCallback] = ..., + callback: _OnBasicRecoverCallback | None = ..., ) -> None: ... def close(self, reply_code: int = ..., reply_text: str = ...) -> None: ... @@ -139,7 +139,7 @@ class Channel: def confirm_delivery( self, ack_nack_callback: _OnAckNackCallback, - callback: Optional[_OnConfirmDeliveryCallback] = ..., + callback: _OnConfirmDeliveryCallback | None = ..., ) -> None: ... @property @@ -150,8 +150,8 @@ class Channel: destination: str, source: str, routing_key: str = ..., - arguments: Optional[Mapping[str, Any]] = ..., - callback: Optional[_OnExchangeBindCallback] = ..., + arguments: Mapping[str, Any] | None = ..., + callback: _OnExchangeBindCallback | None = ..., ) -> None: ... def exchange_declare( @@ -162,27 +162,27 @@ class Channel: durable: bool = ..., auto_delete: bool = ..., internal: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., - callback: Optional[_OnExchangeDeclareCallback] = ..., + arguments: Mapping[str, Any] | None = ..., + callback: _OnExchangeDeclareCallback | None = ..., ) -> None: ... def exchange_delete( self, - exchange: Optional[str] = ..., + exchange: str | None = ..., if_unused: bool = ..., - callback: Optional[_OnExchangeDeleteCallback] = ..., + callback: _OnExchangeDeleteCallback | None = ..., ) -> None: ... def exchange_unbind( self, - destination: Optional[str] = ..., - source: Optional[str] = ..., + destination: str | None = ..., + source: str | None = ..., routing_key: str = ..., - arguments: Optional[Mapping[str, Any]] = ..., - callback: Optional[_OnExchangeUnbindCallback] = ..., + arguments: Mapping[str, Any] | None = ..., + callback: _OnExchangeUnbindCallback | None = ..., ) -> None: ... - def flow(self, active: bool, callback: Optional[_OnFlowCallback] = ...) -> None: ... + def flow(self, active: bool, callback: _OnFlowCallback | None = ...) -> None: ... @property def is_closed(self) -> bool: ... @@ -197,9 +197,9 @@ class Channel: self, queue: str, exchange: str, - routing_key: Optional[str] = ..., - arguments: Optional[Mapping[str, Any]] = ..., - callback: Optional[_OnQueueBindCallback] = ..., + routing_key: str | None = ..., + arguments: Mapping[str, Any] | None = ..., + callback: _OnQueueBindCallback | None = ..., ) -> None: ... def queue_declare( @@ -209,8 +209,8 @@ class Channel: durable: bool = ..., exclusive: bool = ..., auto_delete: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., - callback: Optional[_OnQueueDeclareCallback] = ..., + arguments: Mapping[str, Any] | None = ..., + callback: _OnQueueDeclareCallback | None = ..., ) -> None: ... def queue_delete( @@ -218,27 +218,27 @@ class Channel: queue: str, if_unused: bool = ..., if_empty: bool = ..., - callback: Optional[_OnQueueDeleteCallback] = ..., + callback: _OnQueueDeleteCallback | None = ..., ) -> None: ... def queue_purge( self, queue: str, - callback: Optional[_OnQueuePurgeCallback] = ..., + callback: _OnQueuePurgeCallback | None = ..., ) -> None: ... def queue_unbind( self, queue: str, - exchange: Optional[str] = ..., - routing_key: Optional[str] = ..., - arguments: Optional[Mapping[str, Any]] = ..., - callback: Optional[_OnQueueUnbindCallback] = ..., + exchange: str | None = ..., + routing_key: str | None = ..., + arguments: Mapping[str, Any] | None = ..., + callback: _OnQueueUnbindCallback | None = ..., ) -> None: ... - def tx_commit(self, callback: Optional[_OnTxCommitCallback] = ...) -> None: ... - def tx_rollback(self, callback: Optional[_OnTxRollbackCallback] = ...) -> None: ... - def tx_select(self, callback: Optional[_OnTxSelectCallback] = ...) -> None: ... + def tx_commit(self, callback: _OnTxCommitCallback | None = ...) -> None: ... + def tx_rollback(self, callback: _OnTxRollbackCallback | None = ...) -> None: ... + def tx_select(self, callback: _OnTxSelectCallback | None = ...) -> None: ... class ContentFrameAssembler: def __init__(self) -> None: ... diff --git a/pika-stubs/connection.pyi b/pika-stubs/connection.pyi index ca1b749..f5297d3 100644 --- a/pika-stubs/connection.pyi +++ b/pika-stubs/connection.pyi @@ -1,7 +1,7 @@ from __future__ import annotations import ssl -from typing import Any, Callable, Dict, Mapping, Optional, Union, Type +from typing import Any, Callable, Dict, Mapping, Type from typing_extensions import Literal @@ -30,7 +30,7 @@ _OnConnectionUnblockedCallback = Callable[ None, ] _OnOpenCallback = Callable[['Connection'], None] -_OnOpenErrorCallback = Callable[['Connection', Union[str, Exception]], None] +_OnOpenErrorCallback = Callable[['Connection', str | Exception], None] _OnOpenChannelCallback = Callable[[channel_.Channel], None] @@ -39,13 +39,13 @@ class Parameters: DEFAULT_USERNAME: str = ... DEFAULT_PASSWORD: str = ... - DEFAULT_BLOCKED_CONNECTION_TIMEOUT: Optional[float | int] = ... + DEFAULT_BLOCKED_CONNECTION_TIMEOUT: float | int | None = ... DEFAULT_CHANNEL_MAX: int = ... - DEFAULT_CLIENT_PROPERTIES: Optional[Mapping[str, Any]] = ... + DEFAULT_CLIENT_PROPERTIES: Mapping[str, Any] | None = ... DEFAULT_CREDENTIALS: credentials_._VALID_TYPES = ... DEFAULT_CONNECTION_ATTEMPTS: Literal[1] = ... DEFAULT_FRAME_MAX: int = ... - DEFAULT_HEARTBEAT_TIMEOUT: Optional[Union[int, _OnHeartbeatTimeoutCallback]] = ... + DEFAULT_HEARTBEAT_TIMEOUT: int | _OnHeartbeatTimeoutCallback | None = ... DEFAULT_HOST: str = ... DEFAULT_LOCALE: str = ... DEFAULT_PORT: int = ... @@ -53,23 +53,23 @@ class Parameters: DEFAULT_SOCKET_TIMEOUT: float | int = ... DEFAULT_STACK_TIMEOUT: float | int = ... DEFAULT_SSL: bool = ... - DEFAULT_SSL_OPTIONS: Optional[SSLOptions] = ... + DEFAULT_SSL_OPTIONS: SSLOptions | None = ... DEFAULT_SSL_PORT: int = ... DEFAULT_VIRTUAL_HOST: str = ... - DEFAULT_TCP_OPTIONS: Optional[Mapping[str, Any]] = ... + DEFAULT_TCP_OPTIONS: Mapping[str, Any] | None = ... @property def blocked_connection_timeout(self) -> float | int: ... @blocked_connection_timeout.setter - def blocked_connection_timeout(self, value: Optional[float | int]) -> None: ... + def blocked_connection_timeout(self, value: float | int | None) -> None: ... @property def channel_max(self) -> int: ... @channel_max.setter def channel_max(self, value: int) -> None: ... @property - def client_properties(self) -> Optional[Mapping[str, Any]]: ... + def client_properties(self) -> Mapping[str, Any] | None: ... @client_properties.setter - def client_properties(self, value: Optional[Mapping[str, Any]]) -> None: ... + def client_properties(self, value: Mapping[str, Any] | None) -> None: ... @property def connection_attempts(self) -> int: ... @connection_attempts.setter @@ -83,14 +83,9 @@ class Parameters: @frame_max.setter def frame_max(self, value: int) -> None: ... @property - def heartbeat(self) -> Optional[Union[int, _OnHeartbeatTimeoutCallback]]: ... - + def heartbeat(self) -> int | _OnHeartbeatTimeoutCallback | None: ... @heartbeat.setter - def heartbeat( - self, - value: Optional[Union[int, _OnHeartbeatTimeoutCallback]], - ) -> None: ... - + def heartbeat(self, value: int | _OnHeartbeatTimeoutCallback | None) -> None: ... @property def host(self) -> str: ... @host.setter @@ -108,46 +103,46 @@ class Parameters: @retry_delay.setter def retry_delay(self, value: float | int) -> None: ... @property - def socket_timeout(self) -> Optional[float | int]: ... + def socket_timeout(self) -> float | int | None: ... @socket_timeout.setter - def socket_timeout(self, value: Optional[float | int]) -> None: ... + def socket_timeout(self, value: float | int | None) -> None: ... @property - def stack_timeout(self) -> Optional[float | int]: ... + def stack_timeout(self) -> float | int | None: ... @stack_timeout.setter - def stack_timeout(self, value: Optional[float | int]) -> None: ... + def stack_timeout(self, value: float | int | None) -> None: ... @property - def ssl_options(self) -> Optional[SSLOptions]: ... + def ssl_options(self) -> SSLOptions | None: ... @ssl_options.setter - def ssl_options(self, value: Optional[SSLOptions]) -> None: ... + def ssl_options(self, value: SSLOptions | None) -> None: ... @property def virtual_host(self) -> str: ... @virtual_host.setter def virtual_host(self, value: str) -> None: ... @property - def tcp_options(self) -> Optional[Mapping[str, Any]]: ... + def tcp_options(self) -> Mapping[str, Any] | None: ... @tcp_options.setter - def tcp_options(self, value: Optional[Mapping[str, Any]]) -> None: ... + def tcp_options(self, value: Mapping[str, Any] | None) -> None: ... class ConnectionParameters(Parameters): class _DEFAULT: ... def __init__( self, - host: Union[str, Type[_DEFAULT]] = ..., - port: Union[int, Type[_DEFAULT]] = ..., - virtual_host: Union[str, Type[_DEFAULT]] = ..., - credentials: Union[credentials_._VALID_TYPES, Type[_DEFAULT]] = ..., - channel_max: Union[int, Type[_DEFAULT]] = ..., - frame_max: Union[int, Type[_DEFAULT]] = ..., - heartbeat: Union[int, _OnHeartbeatTimeoutCallback, None, Type[_DEFAULT]] = ..., - ssl_options: Union[SSLOptions, Type[_DEFAULT]] = ..., - connection_attempts: Union[int, Type[_DEFAULT]] = ..., - retry_delay: Union[float | int, Type[_DEFAULT]] = ..., - socket_timeout: Union[float | int, Type[_DEFAULT]] = ..., - stack_timeout: Union[float | int, Type[_DEFAULT]] = ..., - locale: Union[str, Type[_DEFAULT]] = ..., - blocked_connection_timeout: Union[float | int, None, Type[_DEFAULT]] = ..., - client_properties: Union[Mapping[str, Any], None, Type[_DEFAULT]] = ..., - tcp_options: Union[Mapping[str, Any], None, Type[_DEFAULT]] = ..., + host: str | Type[_DEFAULT] = ..., + port: int | Type[_DEFAULT] = ..., + virtual_host: str | Type[_DEFAULT] = ..., + credentials: credentials_._VALID_TYPES | Type[_DEFAULT] = ..., + channel_max: int | Type[_DEFAULT] = ..., + frame_max: int | Type[_DEFAULT] = ..., + heartbeat: int | None | _OnHeartbeatTimeoutCallback | Type[_DEFAULT] = ..., + ssl_options: SSLOptions | Type[_DEFAULT] = ..., + connection_attempts: int | Type[_DEFAULT] = ..., + retry_delay: float | int | Type[_DEFAULT] = ..., + socket_timeout: float | int | Type[_DEFAULT] = ..., + stack_timeout: float | int | Type[_DEFAULT] = ..., + locale: str | Type[_DEFAULT] = ..., + blocked_connection_timeout: float | int | None | Type[_DEFAULT] = ..., + client_properties: Mapping[str, Any] | None | Type[_DEFAULT] = ..., + tcp_options: Mapping[str, Any] | None | Type[_DEFAULT] = ..., **kwargs: Any, ): ... @@ -160,9 +155,9 @@ class URLParameters(Parameters): class SSLOptions: context: ssl.SSLContext = ... - server_hostname: Optional[str] = ... + server_hostname: str | None = ... - def __init__(self, context: ssl.SSLContext, server_hostname: Optional[str] = ...): ... + def __init__(self, context: ssl.SSLContext, server_hostname: str | None = ...): ... class Connection(compat.AbstractBase): @@ -179,12 +174,12 @@ class Connection(compat.AbstractBase): CONNECTION_OPEN: int = ... CONNECTION_CLOSING: int = ... - connection_state: Optional[str] = ... - params: Optional[Parameters] = ... + connection_state: str | None = ... + params: Parameters | None = ... callbacks: callback.CallbackManager = ... - server_capabilities: Optional[Mapping[str, Any]] = ... - server_properties: Optional[Dict[str, Any]] = ... - known_hosts: Optional[str] = ... + server_capabilities: Mapping[str, Any] | None = ... + server_properties: Dict[str, Any] | None = ... + known_hosts: str | None = ... bytes_sent: int = ... bytes_received: int = ... @@ -193,39 +188,18 @@ class Connection(compat.AbstractBase): def __init__( self, - parameters: Optional[Parameters] = ..., - on_open_callback: Optional[_OnOpenCallback] = ..., - on_open_error_callback: Optional[_OnOpenErrorCallback] = ..., - on_close_callback: Optional[_OnCloseCallback] = ..., + parameters: Parameters | None = ..., + on_open_callback: _OnOpenCallback | None = ..., + on_open_error_callback: _OnOpenErrorCallback | None = ..., + on_close_callback: _OnCloseCallback | None = ..., internal_connection_workflow: bool = ..., ) -> None: ... - def add_on_close_callback(self, callback: _OnCloseCallback) -> None: ... - - def add_on_connection_blocked_callback( - self, - callback: _OnConnectionBlockedCallback, - ) -> None: ... - - def add_on_connection_unblocked_callback( - self, - callback: _OnConnectionUnblockedCallback, - ) -> None: ... - + def add_on_connection_blocked_callback( self, callback: _OnConnectionBlockedCallback, ) -> None: ... + def add_on_connection_unblocked_callback( self, callback: _OnConnectionUnblockedCallback, ) -> None: ... def add_on_open_callback(self, callback: _OnOpenCallback) -> None: ... - - def add_on_open_error_callback( - self, - callback: _OnOpenErrorCallback, - remove_default: bool = ..., - ) -> None: ... - - def channel( - self, - channel_number: Optional[int] = ..., - on_open_callback: Optional[_OnOpenChannelCallback] = ..., - ) -> channel_.Channel: ... - + def add_on_open_error_callback( self, callback: _OnOpenErrorCallback, remove_default: bool = ..., ) -> None: ... + def channel( self, channel_number: int | None = ..., on_open_callback: _OnOpenChannelCallback | None = ..., ) -> channel_.Channel: ... def close(self, reply_code: int = ..., reply_text: str = ...) -> None: ... @property diff --git a/pika-stubs/credentials.pyi b/pika-stubs/credentials.pyi index 72ee43d..5385d5b 100644 --- a/pika-stubs/credentials.pyi +++ b/pika-stubs/credentials.pyi @@ -1,4 +1,4 @@ -from typing import Optional, Tuple, Union, Type +from typing import Tuple, Type from . import spec @@ -16,7 +16,7 @@ class PlainCredentials: def response_for( self, start: spec.Connection.Start, - ) -> Tuple[Optional[str], Optional[str]]: ... + ) -> Tuple[str | None, str | None]: ... def erase_credentials(self) -> None: ... @@ -30,10 +30,10 @@ class ExternalCredentials: def response_for( self, start: spec.Connection.Start, - ) -> Tuple[Optional[str], Optional[str]]: ... + ) -> Tuple[str | None, str | None]: ... def erase_credentials(self) -> None: ... -_VALID_TYPES = Union[PlainCredentials, ExternalCredentials] +_VALID_TYPES = PlainCredentials | ExternalCredentials VALID_TYPES: list[_VALID_TYPES] diff --git a/pika-stubs/frame.pyi b/pika-stubs/frame.pyi index fecc731..14c77cd 100644 --- a/pika-stubs/frame.pyi +++ b/pika-stubs/frame.pyi @@ -1,4 +1,4 @@ -from typing import Any, Generic, Optional, Tuple, TypeVar +from typing import Any, Generic, Tuple, TypeVar from . import amqp_object, spec @@ -72,11 +72,11 @@ class ProtocolHeader(amqp_object.AMQPObject): def __init__( self, - major: Optional[int] = ..., - minor: Optional[int] = ..., - revision: Optional[int] = ..., + major: int | None = ..., + minor: int | None = ..., + revision: int | None = ..., ) -> None: ... def marshal(self) -> bytes: ... -def decode_frame(data_in: bytes) -> Tuple[int, Optional[Frame]]: ... +def decode_frame(data_in: bytes) -> Tuple[int, Frame | None]: ... diff --git a/pika-stubs/spec.pyi b/pika-stubs/spec.pyi index 2a77196..b4f6147 100644 --- a/pika-stubs/spec.pyi +++ b/pika-stubs/spec.pyi @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Any, List, Mapping, Optional, Type +from typing import Any, List, Mapping, Type from typing_extensions import Literal @@ -55,7 +55,7 @@ class Connection(amqp_object.Class): version_major: int = ... version_minor: int = ... - server_properties: Optional[Mapping[str, Any]] = ... + server_properties: Mapping[str, Any] | None = ... mechanisms: str = ... locales: str = ... @@ -63,7 +63,7 @@ class Connection(amqp_object.Class): self, version_major: int = ..., version_minor: int = ..., - server_properties: Optional[Mapping[str, Any]] = ..., + server_properties: Mapping[str, Any] | None = ..., mechanisms: str = ..., locales: str = ..., ) -> None: ... @@ -79,16 +79,16 @@ class Connection(amqp_object.Class): INDEX: Literal[0x000A000B] NAME: Literal['Connection.StartOk'] - client_properties: Optional[Mapping[str, Any]] = ... + client_properties: Mapping[str, Any] | None = ... mechanism: str = ... - response: Optional[str] = ... + response: str | None = ... locale: str = ... def __init__( self, - client_properties: Optional[Mapping[str, Any]] = ..., + client_properties: Mapping[str, Any] | None = ..., mechanism: str = ..., - response: Optional[str] = ..., + response: str | None = ..., locale: str = ..., ) -> None: ... @@ -103,9 +103,9 @@ class Connection(amqp_object.Class): INDEX: Literal[0x000A0014] NAME: Literal['Connection.Secure'] - challenge: Optional[str] = ... + challenge: str | None = ... - def __init__(self, challenge: Optional[str] = ...) -> None: ... + def __init__(self, challenge: str | None = ...) -> None: ... @property def synchronous(self) -> bool: ... @@ -118,9 +118,9 @@ class Connection(amqp_object.Class): INDEX: Literal[0x000A0015] NAME: Literal['Connection.SecureOk'] - response: Optional[str] = ... + response: str | None = ... - def __init__(self, response: Optional[str] = ...) -> None: ... + def __init__(self, response: str | None = ...) -> None: ... @property def synchronous(self) -> bool: ... @@ -209,17 +209,17 @@ class Connection(amqp_object.Class): INDEX: Literal[0x000A0032] NAME: Literal['Connection.Close'] - reply_code: Optional[int] = ... + reply_code: int | None = ... reply_text: str = ... - class_id: Optional[int] = ... - method_id: Optional[int] = ... + class_id: int | None = ... + method_id: int | None = ... def __init__( self, - reply_code: Optional[int] = ..., + reply_code: int | None = ..., reply_text: str = ..., - class_id: Optional[int] = ..., - method_id: Optional[int] = ..., + class_id: int | None = ..., + method_id: int | None = ..., ) -> None: ... @property @@ -306,9 +306,9 @@ class Channel(amqp_object.Class): INDEX: Literal[0x00140014] NAME: Literal['Channel.Flow'] - active: Optional[bool] = ... + active: bool | None = ... - def __init__(self, active: Optional[bool] = ...) -> None: ... + def __init__(self, active: bool | None = ...) -> None: ... @property def synchronous(self) -> bool: ... @@ -321,9 +321,9 @@ class Channel(amqp_object.Class): INDEX: Literal[0x00140015] NAME: Literal['Channel.FlowOk'] - active: Optional[bool] = ... + active: bool | None = ... - def __init__(self, active: Optional[bool] = ...) -> None: ... + def __init__(self, active: bool | None = ...) -> None: ... @property def synchronous(self) -> bool: ... @@ -336,17 +336,17 @@ class Channel(amqp_object.Class): INDEX: Literal[0x00140028] NAME: Literal['Channel.Close'] - reply_code: Optional[int] = ... + reply_code: int | None = ... reply_text: str = ... - class_id: Optional[int] = ... - method_id: Optional[int] = ... + class_id: int | None = ... + method_id: int | None = ... def __init__( self, - reply_code: Optional[int] = ..., + reply_code: int | None = ..., reply_text: str = ..., - class_id: Optional[int] = ..., - method_id: Optional[int] = ..., + class_id: int | None = ..., + method_id: int | None = ..., ) -> None: ... @property @@ -427,26 +427,26 @@ class Exchange(amqp_object.Class): NAME: Literal['Exchange.Declare'] ticket: int = ... - exchange: Optional[str] = ... + exchange: str | None = ... type: str = ... passive: bool = ... durable: bool = ... auto_delete: bool = ... internal: bool = ... nowait: bool = ... - arguments: Optional[Mapping[str, Any]] = ... + arguments: Mapping[str, Any] | None = ... def __init__( self, ticket: int = ..., - exchange: Optional[str] = ..., + exchange: str | None = ..., type: ExchangeType = ..., passive: bool = ..., durable: bool = ..., auto_delete: bool = ..., internal: bool = ..., nowait: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> None: ... @property @@ -472,14 +472,14 @@ class Exchange(amqp_object.Class): NAME: Literal['Exchange.Delete'] ticket: int = ... - exchange: Optional[str] = ... + exchange: str | None = ... if_unused: bool = ... nowait: bool = ... def __init__( self, ticket: int = ..., - exchange: Optional[str] = ..., + exchange: str | None = ..., if_unused: bool = ..., nowait: bool = ..., ) -> None: ... @@ -507,20 +507,20 @@ class Exchange(amqp_object.Class): NAME: Literal['Exchange.Bind'] ticket: int = ... - destination: Optional[str] = ... - source: Optional[str] = ... + destination: str | None = ... + source: str | None = ... routing_key: str = ... nowait: bool = ... - arguments: Optional[Mapping[str, Any]] = ... + arguments: Mapping[str, Any] | None = ... def __init__( self, ticket: int = ..., - destination: Optional[str] = ..., - source: Optional[str] = ..., + destination: str | None = ..., + source: str | None = ..., routing_key: str = ..., nowait: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> None: ... @property @@ -546,20 +546,20 @@ class Exchange(amqp_object.Class): NAME: Literal['Exchange.Unbind'] ticket: int = ... - destination: Optional[str] = ... - source: Optional[str] = ... + destination: str | None = ... + source: str | None = ... routing_key: str = ... nowait: bool = ... - arguments: Optional[Mapping[str, Any]] = ... + arguments: Mapping[str, Any] | None = ... def __init__( self, ticket: int = ..., - destination: Optional[str] = ..., - source: Optional[str] = ..., + destination: str | None = ..., + source: str | None = ..., routing_key: str = ..., nowait: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> None: ... @property @@ -597,7 +597,7 @@ class Queue(amqp_object.Class): exclusive: bool = ... auto_delete: bool = ... nowait: bool = ... - arguments: Optional[Mapping[str, Any]] = ... + arguments: Mapping[str, Any] | None = ... def __init__( self, @@ -608,7 +608,7 @@ class Queue(amqp_object.Class): exclusive: bool = ..., auto_delete: bool = ..., nowait: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> None: ... @property @@ -622,15 +622,15 @@ class Queue(amqp_object.Class): INDEX: Literal[0x0032000B] NAME: Literal['Queue.DeclareOk'] - queue: Optional[str] = ... - message_count: Optional[int] = ... - consumer_count: Optional[int] = ... + queue: str | None = ... + message_count: int | None = ... + consumer_count: int | None = ... def __init__( self, - queue: Optional[str] = ..., - message_count: Optional[int] = ..., - consumer_count: Optional[int] = ..., + queue: str | None = ..., + message_count: int | None = ..., + consumer_count: int | None = ..., ) -> None: ... @property @@ -646,19 +646,19 @@ class Queue(amqp_object.Class): ticket: int = ... queue: str = ... - exchange: Optional[str] = ... + exchange: str | None = ... routing_key: str = ... nowait: bool = ... - arguments: Optional[Mapping[str, Any]] = ... + arguments: Mapping[str, Any] | None = ... def __init__( self, ticket: int = ..., queue: str = ..., - exchange: Optional[str] = ..., + exchange: str | None = ..., routing_key: str = ..., nowait: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> None: ... @property @@ -705,9 +705,9 @@ class Queue(amqp_object.Class): INDEX: Literal[0x0032001F] NAME: Literal['Queue.PurgeOk'] - message_count: Optional[int] = ... + message_count: int | None = ... - def __init__(self, message_count: Optional[int] = ...) -> None: ... + def __init__(self, message_count: int | None = ...) -> None: ... @property def synchronous(self) -> bool: ... @@ -746,9 +746,9 @@ class Queue(amqp_object.Class): INDEX: Literal[0x00320029] NAME: Literal['Queue.DeleteOk'] - message_count: Optional[int] = ... + message_count: int | None = ... - def __init__(self, message_count: Optional[int] = ...) -> None: ... + def __init__(self, message_count: int | None = ...) -> None: ... @property def synchronous(self) -> bool: ... @@ -763,17 +763,17 @@ class Queue(amqp_object.Class): ticket: int = ... queue: str = ... - exchange: Optional[str] = ... + exchange: str | None = ... routing_key: str = ... - arguments: Optional[Mapping[str, Any]] = ... + arguments: Mapping[str, Any] | None = ... def __init__( self, ticket: int = ..., queue: str = ..., - exchange: Optional[str] = ..., + exchange: str | None = ..., routing_key: str = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> None: ... @property @@ -844,7 +844,7 @@ class Basic(amqp_object.Class): no_ack: bool = ... exclusive: bool = ... nowait: bool = ... - arguments: Optional[Mapping[str, Any]] = ... + arguments: Mapping[str, Any] | None = ... def __init__( self, @@ -855,7 +855,7 @@ class Basic(amqp_object.Class): no_ack: bool = ..., exclusive: bool = ..., nowait: bool = ..., - arguments: Optional[Mapping[str, Any]] = ..., + arguments: Mapping[str, Any] | None = ..., ) -> None: ... @property @@ -869,9 +869,9 @@ class Basic(amqp_object.Class): INDEX: Literal[0x003C0015] NAME: Literal['Basic.ConsumeOk'] - consumer_tag: Optional[int] = ... + consumer_tag: int | None = ... - def __init__(self, consumer_tag: Optional[int] = ...) -> None: ... + def __init__(self, consumer_tag: int | None = ...) -> None: ... @property def synchronous(self) -> bool: ... @@ -884,10 +884,10 @@ class Basic(amqp_object.Class): INDEX: Literal[0x003C001E] NAME: Literal['Basic.Cancel'] - consumer_tag: Optional[int] = ... + consumer_tag: int | None = ... nowait: bool = ... - def __init__(self, consumer_tag: Optional[int] = ..., nowait: bool = ...) -> None: ... + def __init__(self, consumer_tag: int | None = ..., nowait: bool = ...) -> None: ... @property def synchronous(self) -> bool: ... @@ -900,9 +900,9 @@ class Basic(amqp_object.Class): INDEX: Literal[0x003C001F] NAME: Literal['Basic.CancelOk'] - consumer_tag: Optional[int] = ... + consumer_tag: int | None = ... - def __init__(self, consumer_tag: Optional[int] = ...) -> None: ... + def __init__(self, consumer_tag: int | None = ...) -> None: ... @property def synchronous(self) -> bool: ... @@ -941,17 +941,17 @@ class Basic(amqp_object.Class): INDEX: Literal[0x003C0032] NAME: Literal['Basic.Return'] - reply_code: Optional[int] = ... + reply_code: int | None = ... reply_text: str = ... - exchange: Optional[str] = ... - routing_key: Optional[str] = ... + exchange: str | None = ... + routing_key: str | None = ... def __init__( self, - reply_code: Optional[int] = ..., + reply_code: int | None = ..., reply_text: str = ..., - exchange: Optional[str] = ..., - routing_key: Optional[str] = ..., + exchange: str | None = ..., + routing_key: str | None = ..., ) -> None: ... @property @@ -965,19 +965,19 @@ class Basic(amqp_object.Class): INDEX: Literal[0x003C003C] NAME: Literal['Basic.Deliver'] - consumer_tag: Optional[str] = ... - delivery_tag: Optional[int] = ... + consumer_tag: str | None = ... + delivery_tag: int | None = ... redelivered: bool = ... - exchange: Optional[str] = ... - routing_key: Optional[str] = ... + exchange: str | None = ... + routing_key: str | None = ... def __init__( self, - consumer_tag: Optional[str] = ..., - delivery_tag: Optional[int] = ..., + consumer_tag: str | None = ..., + delivery_tag: int | None = ..., redelivered: bool = ..., - exchange: Optional[str] = ..., - routing_key: Optional[str] = ..., + exchange: str | None = ..., + routing_key: str | None = ..., ) -> None: ... @property @@ -1013,19 +1013,19 @@ class Basic(amqp_object.Class): INDEX: Literal[0x003C0047] NAME: Literal['Basic.GetOk'] - delivery_tag: Optional[int] = ... + delivery_tag: int | None = ... redelivered: bool = ... - exchange: Optional[str] = ... - routing_key: Optional[str] = ... - message_count: Optional[int] = ... + exchange: str | None = ... + routing_key: str | None = ... + message_count: int | None = ... def __init__( self, - delivery_tag: Optional[int] = ..., + delivery_tag: int | None = ..., redelivered: bool = ..., - exchange: Optional[str] = ..., - routing_key: Optional[str] = ..., - message_count: Optional[int] = ..., + exchange: str | None = ..., + routing_key: str | None = ..., + message_count: int | None = ..., ) -> None: ... @property @@ -1070,10 +1070,10 @@ class Basic(amqp_object.Class): INDEX: Literal[0x003C005A] NAME: Literal['Basic.Reject'] - delivery_tag: Optional[int] = ... + delivery_tag: int | None = ... requeue: bool = ... - def __init__(self, delivery_tag: Optional[int] = ..., requeue: bool = ...) -> None: ... + def __init__(self, delivery_tag: int | None = ..., requeue: bool = ...) -> None: ... @property def synchronous(self) -> bool: ... @@ -1271,37 +1271,37 @@ class BasicProperties(amqp_object.Properties): FLAG_APP_ID: int = ... FLAG_CLUSTER_ID: int = ... - content_type: Optional[str] = ... - content_encoding: Optional[str] = ... - headers: Optional[Mapping[str, Any]] = ... - delivery_mode: Optional[int] = ... - priority: Optional[int] = ... - correlation_id: Optional[str] = ... - reply_to: Optional[str] = ... - expiration: Optional[str] = ... - message_id: Optional[str] = ... - timestamp: Optional[int] = ... - type: Optional[str] = ... - user_id: Optional[str] = ... - app_id: Optional[str] = ... - cluster_id: Optional[str] = ... + content_type: str | None = ... + content_encoding: str | None = ... + headers: Mapping[str, Any] | None = ... + delivery_mode: int | None = ... + priority: int | None = ... + correlation_id: str | None = ... + reply_to: str | None = ... + expiration: str | None = ... + message_id: str | None = ... + timestamp: int | None = ... + type: str | None = ... + user_id: str | None = ... + app_id: str | None = ... + cluster_id: str | None = ... def __init__( self, - content_type: Optional[str] = ..., - content_encoding: Optional[str] = ..., - headers: Optional[Mapping[str, Any]] = ..., - delivery_mode: Optional[int] = ..., - priority: Optional[int] = ..., - correlation_id: Optional[str] = ..., - reply_to: Optional[str] = ..., - expiration: Optional[str] = ..., - message_id: Optional[str] = ..., - timestamp: Optional[int] = ..., - type: Optional[str] = ..., - user_id: Optional[str] = ..., - app_id: Optional[str] = ..., - cluster_id: Optional[str] = ..., + content_type: str | None = ..., + content_encoding: str | None = ..., + headers: Mapping[str, Any] | None = ..., + delivery_mode: int | None = ..., + priority: int | None = ..., + correlation_id: str | None = ..., + reply_to: str | None = ..., + expiration: str | None = ..., + message_id: str | None = ..., + timestamp: int | None = ..., + type: str | None = ..., + user_id: str | None = ..., + app_id: str | None = ..., + cluster_id: str | None = ..., ) -> None: ... def decode(self, encoded: bytes, offset: int = ...) -> BasicProperties: ... From 8aa2d2b1026e850a2b2d329259df2683dede6caa Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Mon, 17 Jan 2022 15:01:30 -0600 Subject: [PATCH 07/11] use built-in collection types --- pika-stubs/adapters/asyncio_connection.pyi | 5 +- pika-stubs/adapters/base_connection.pyi | 10 +- pika-stubs/adapters/blocking_connection.pyi | 30 ++-- pika-stubs/adapters/select_connection.pyi | 15 +- pika-stubs/adapters/tornado_connection.pyi | 8 +- pika-stubs/adapters/twisted_connection.pyi | 28 ++-- .../adapters/utils/io_services_utils.pyi | 5 +- pika-stubs/adapters/utils/nbio_interface.pyi | 14 +- .../utils/selector_ioloop_adapter.pyi | 28 ++-- pika-stubs/callback.pyi | 8 +- pika-stubs/channel.pyi | 27 ++-- pika-stubs/compat.pyi | 15 +- pika-stubs/connection.pyi | 22 +-- pika-stubs/credentials.pyi | 9 +- pika-stubs/exceptions.pyi | 5 +- pika-stubs/frame.pyi | 11 +- pika-stubs/spec.pyi | 135 +++++++++--------- 17 files changed, 213 insertions(+), 162 deletions(-) diff --git a/pika-stubs/adapters/asyncio_connection.pyi b/pika-stubs/adapters/asyncio_connection.pyi index 9e83c0d..2fed447 100644 --- a/pika-stubs/adapters/asyncio_connection.pyi +++ b/pika-stubs/adapters/asyncio_connection.pyi @@ -1,5 +1,8 @@ +from __future__ import annotations + import asyncio -from typing import Callable, Sequence +from collections.abc import Sequence +from typing import Callable from .. import connection from . import base_connection diff --git a/pika-stubs/adapters/base_connection.pyi b/pika-stubs/adapters/base_connection.pyi index 7774698..5410793 100644 --- a/pika-stubs/adapters/base_connection.pyi +++ b/pika-stubs/adapters/base_connection.pyi @@ -1,8 +1,14 @@ +from __future__ import annotations + import abc -from typing import Callable, Generic, Sequence, TypeVar +from collections.abc import Sequence +from typing import Callable +from typing import Generic +from typing import TypeVar from .. import connection -from .utils import connection_workflow, nbio_interface +from .utils import connection_workflow +from .utils import nbio_interface _OnCloseCallback = Callable[['BaseConnection', Exception], None] _OnOpenCallback = Callable[['BaseConnection'], None] diff --git a/pika-stubs/adapters/blocking_connection.pyi b/pika-stubs/adapters/blocking_connection.pyi index e8f647e..066a791 100644 --- a/pika-stubs/adapters/blocking_connection.pyi +++ b/pika-stubs/adapters/blocking_connection.pyi @@ -1,12 +1,20 @@ from __future__ import annotations import types -from typing import Any, Callable, Iterator, List, Mapping, Tuple, Type, Sequence - -from .. import channel, connection, frame, spec +from collections.abc import Mapping +from collections.abc import Sequence +from typing import Any +from typing import AnyStr +from typing import Callable +from typing import Iterator +from typing import Type + +from .. import channel +from .. import connection +from .. import frame +from .. import spec from ..exchange_type import ExchangeType - class BlockingConnection: def __init__( @@ -109,7 +117,7 @@ class BlockingChannel: @property def is_open(self) -> bool: ... @property - def consumer_tags(self) -> List[str]: ... + def consumer_tags(self) -> list[str]: ... def close(self, reply_code: int = ..., reply_text: str = ...) -> None: ... def flow(self, active: bool) -> bool: ... @@ -135,8 +143,8 @@ class BlockingChannel: arguments: Mapping[str, Any] | None = ..., ) -> str: ... - def basic_cancel(self, consumer_tag: str) -> List[ - Tuple[spec.Basic.Deliver, spec.BasicProperties, bytes], + def basic_cancel(self, consumer_tag: str) -> list[ + tuple[spec.Basic.Deliver, spec.BasicProperties, bytes], ]: ... def start_consuming(self) -> None: ... def stop_consuming(self, consumer_tag: str | None = ...) -> None: ... @@ -149,12 +157,12 @@ class BlockingChannel: arguments: Mapping[str, Any] | None = ..., inactivity_timeout: float | None = ..., ) -> Iterator[ - Tuple[ + tuple[ spec.Basic.Deliver, spec.BasicProperties, bytes, ] | - Tuple[ + tuple[ None, None, None, @@ -174,7 +182,7 @@ class BlockingChannel: requeue: bool = ..., ) -> None: ... - def basic_get(self, queue: str, auto_ack: bool = ...) -> Tuple[ + def basic_get(self, queue: str, auto_ack: bool = ...) -> tuple[ spec.Basic.GetOk | None, spec.BasicProperties | None, str | None, @@ -184,7 +192,7 @@ class BlockingChannel: self, exchange: str, routing_key: str, - body: bytes | str, + body: AnyStr, properties: spec.BasicProperties | None = ..., mandatory: bool = ..., ) -> None: ... diff --git a/pika-stubs/adapters/select_connection.pyi b/pika-stubs/adapters/select_connection.pyi index b73765c..a8d78df 100644 --- a/pika-stubs/adapters/select_connection.pyi +++ b/pika-stubs/adapters/select_connection.pyi @@ -1,11 +1,18 @@ from __future__ import annotations import abc -from typing import Any, AnyStr, Callable, IO, Sequence - -from .. import compat, connection +from collections.abc import Sequence +from typing import IO +from typing import Any +from typing import AnyStr +from typing import Callable + +from .. import compat +from .. import connection from . import base_connection -from .utils import connection_workflow, nbio_interface, selector_ioloop_adapter +from .utils import connection_workflow +from .utils import nbio_interface +from .utils import selector_ioloop_adapter SELECT_TYPE: str | None diff --git a/pika-stubs/adapters/tornado_connection.pyi b/pika-stubs/adapters/tornado_connection.pyi index 8c3e94b..a90027b 100644 --- a/pika-stubs/adapters/tornado_connection.pyi +++ b/pika-stubs/adapters/tornado_connection.pyi @@ -1,10 +1,14 @@ -from typing import Callable, Sequence +from __future__ import annotations + +from collections.abc import Sequence +from typing import Callable import tornado.ioloop from .. import connection from . import base_connection -from .utils import connection_workflow, nbio_interface +from .utils import connection_workflow +from .utils import nbio_interface _OnCloseCallback = Callable[['TornadoConnection', Exception], None] _OnOpenCallback = Callable[['TornadoConnection'], None] diff --git a/pika-stubs/adapters/twisted_connection.pyi b/pika-stubs/adapters/twisted_connection.pyi index e679716..bcbd5f4 100644 --- a/pika-stubs/adapters/twisted_connection.pyi +++ b/pika-stubs/adapters/twisted_connection.pyi @@ -1,29 +1,27 @@ from __future__ import annotations -from typing import ( - Any, - Callable, - List, - Mapping, - NamedTuple, - Sequence, - TypeVar, - Tuple, -) +from collections.abc import Mapping +from collections.abc import Sequence +from typing import Any +from typing import AnyStr +from typing import Callable +from typing import NamedTuple +from typing import TypeVar import twisted.internet.base import twisted.internet.defer import twisted.internet.interfaces import twisted.internet.protocol import twisted.python.failure -from twisted.internet.defer import Deferred, DeferredQueue +from twisted.internet.defer import Deferred +from twisted.internet.defer import DeferredQueue from .. import amqp_object from .. import frame from .. import spec +from ..channel import Channel from ..connection import Connection from ..connection import Parameters -from ..channel import Channel from ..exchange_type import ExchangeType _T = TypeVar("_T") @@ -72,7 +70,7 @@ class TwistedChannel: @property def flow_active(self) -> bool: ... @property - def consumer_tags(self) -> List[str]: ... + def consumer_tags(self) -> list[str]: ... def callback_deferred( self, @@ -93,7 +91,7 @@ class TwistedChannel: exclusive: bool = ..., consumer_tag: str | None = ..., arguments: Mapping[str, Any] | None = ..., - ) -> Deferred[Tuple[ClosableDeferredQueue[ReceivedMessage], str]]: ... + ) -> Deferred[tuple[ClosableDeferredQueue[ReceivedMessage], str]]: ... # ReceivedMessage.method: spec.Basic.GetOk def basic_get( @@ -113,7 +111,7 @@ class TwistedChannel: self, exchange: str, routing_key: str, - body: bytes | str, + body: AnyStr, properties: spec.BasicProperties | None = ..., mandatory: bool = ..., ) -> Deferred[None]: ... diff --git a/pika-stubs/adapters/utils/io_services_utils.pyi b/pika-stubs/adapters/utils/io_services_utils.pyi index 06f45b3..df95ae5 100644 --- a/pika-stubs/adapters/utils/io_services_utils.pyi +++ b/pika-stubs/adapters/utils/io_services_utils.pyi @@ -2,7 +2,8 @@ from __future__ import annotations import ssl from socket import socket -from typing import Any, Callable, Tuple +from typing import Any +from typing import Callable from . import nbio_interface @@ -25,7 +26,7 @@ class StreamingConnectionMixin: self, protocol_factory: Callable[[], nbio_interface.AbstractStreamProtocol], sock: socket, - on_done: Callable[[ BaseException | Tuple[ nbio_interface.AbstractStreamTransport, nbio_interface.AbstractStreamProtocol]], None], + on_done: Callable[[ BaseException | tuple[ nbio_interface.AbstractStreamTransport, nbio_interface.AbstractStreamProtocol]], None], ssl_context: ssl.SSLContext | None = ..., server_hostname: str | None = ..., ) -> nbio_interface.AbstractIOReference: ... diff --git a/pika-stubs/adapters/utils/nbio_interface.pyi b/pika-stubs/adapters/utils/nbio_interface.pyi index 8587bba..1f33927 100644 --- a/pika-stubs/adapters/utils/nbio_interface.pyi +++ b/pika-stubs/adapters/utils/nbio_interface.pyi @@ -2,8 +2,14 @@ from __future__ import annotations import abc import ssl -from socket import AddressFamily, SocketKind, socket -from typing import Any, AnyStr, Callable, IO, List, Text, Tuple +from socket import AddressFamily +from socket import SocketKind +from socket import socket +from typing import IO +from typing import Any +from typing import AnyStr +from typing import Callable +from typing import Text from ... import compat @@ -30,7 +36,7 @@ class AbstractIOServices(compat.AbstractBase): on_done: Callable[ [ BaseException | - List[Tuple[AddressFamily, SocketKind, int, str, Tuple[Any, ...]]], + list[tuple[AddressFamily, SocketKind, int, str, tuple[Any, ...]]], ], None, ], @@ -56,7 +62,7 @@ class AbstractIOServices(compat.AbstractBase): on_done: Callable[ [ BaseException | - Tuple[AbstractStreamTransport, AbstractStreamProtocol], + tuple[AbstractStreamTransport, AbstractStreamProtocol], ], None, ], diff --git a/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi b/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi index 702cd5f..ae0b50b 100644 --- a/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi +++ b/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi @@ -1,18 +1,18 @@ +from __future__ import annotations + import abc -from socket import AddressFamily, SocketKind -from typing import ( - Any, - AnyStr, - Callable, - Generic, - IO, - List, - Text, - Tuple, - TypeVar, -) +from socket import AddressFamily +from socket import SocketKind +from typing import IO +from typing import Any +from typing import AnyStr +from typing import Callable +from typing import Generic +from typing import Text +from typing import TypeVar -from . import io_services_utils, nbio_interface +from . import io_services_utils +from . import nbio_interface _Timeout = TypeVar('_Timeout', bound=object) @@ -84,7 +84,7 @@ class SelectorIOServicesAdapter( on_done: Callable[ [ BaseException | - List[Tuple[AddressFamily, SocketKind, int, str, Tuple[Any, ...]]], + list[tuple[AddressFamily, SocketKind, int, str, tuple[Any, ...]]], ], None, ], diff --git a/pika-stubs/callback.pyi b/pika-stubs/callback.pyi index 0e41e0e..33de281 100644 --- a/pika-stubs/callback.pyi +++ b/pika-stubs/callback.pyi @@ -1,4 +1,8 @@ -from typing import Any, Callable, Mapping, Tuple +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any +from typing import Callable from . import amqp_object @@ -30,7 +34,7 @@ class CallbackManager: one_shot: bool = ..., only_caller: _Caller | None = ..., arguments: Mapping[str, Any] | None = ..., - ) -> Tuple[_Prefix, Any]: ... + ) -> tuple[_Prefix, Any]: ... def clear(self) -> None: ... def cleanup(self, prefix: _Prefix) -> bool: ... diff --git a/pika-stubs/channel.pyi b/pika-stubs/channel.pyi index 7a5b41e..81c017a 100644 --- a/pika-stubs/channel.pyi +++ b/pika-stubs/channel.pyi @@ -1,15 +1,16 @@ from __future__ import annotations -from typing import Any, Callable, List, Mapping, Sequence, Tuple - +from collections.abc import Mapping +from collections.abc import Sequence +from typing import Any +from typing import AnyStr +from typing import Callable from typing_extensions import Literal -from . import ( - callback, - connection as connection_, - frame, - spec, -) +from . import callback +from . import connection as connection_ +from . import frame +from . import spec from .exchange_type import ExchangeType MAX_CHANNELS: Literal[65535] # per AMQP 0.9.1 spec. @@ -113,7 +114,7 @@ class Channel: self, exchange: str, routing_key: str, - body: bytes | str, + body: AnyStr, properties: spec.BasicProperties | None = ..., mandatory: bool = ..., ) -> None: ... @@ -143,7 +144,7 @@ class Channel: ) -> None: ... @property - def consumer_tags(self) -> List[str]: ... + def consumer_tags(self) -> list[str]: ... def exchange_bind( self, @@ -244,9 +245,9 @@ class ContentFrameAssembler: def __init__(self) -> None: ... def process( self, frame_value: frame.Method | frame.Header | frame.Body - ) -> Tuple[frame.Method, frame.Header, bytes] | None: ... - def _finish(self) -> Tuple[frame.Method, frame.Header, bytes]: ... + ) -> tuple[frame.Method, frame.Header, bytes] | None: ... + def _finish(self) -> tuple[frame.Method, frame.Header, bytes]: ... - def _handle_body_frame(self, body_frame) -> Tuple[frame.Method, frame.Header, bytes] | None: ... + def _handle_body_frame(self, body_frame) -> tuple[frame.Method, frame.Header, bytes] | None: ... def _reset(self) -> None: ... diff --git a/pika-stubs/compat.pyi b/pika-stubs/compat.pyi index 7072c66..caa58bb 100644 --- a/pika-stubs/compat.pyi +++ b/pika-stubs/compat.pyi @@ -2,7 +2,12 @@ from __future__ import annotations import abc import re -from typing import Tuple, Type, KeysView, ValuesView, ItemsView, Any +from typing import Any +from typing import AnyStr +from typing import ItemsView +from typing import KeysView +from typing import Type +from typing import ValuesView PY2: bool PY3: bool @@ -17,8 +22,8 @@ class AbstractBase(metaclass=abc.ABCMeta): ... SOCKET_ERROR: Type[Exception] SOL_TCP: int -basestring: Tuple[Type[str]] -str_or_bytes: Tuple[Type[str], Type[bytes]] +basestring: tuple[Type[str]] +str_or_bytes: tuple[Type[str], Type[bytes]] xrange: Type[range] unicode_type: Type[str] @@ -35,12 +40,12 @@ class long(int): def canonical_str(value) -> str: ... def is_integer(value: Any) -> bool: ... -def as_bytes(value: str | bytes) -> bytes: ... +def as_bytes(value: AnyStr) -> bytes: ... def to_digit(value): ... def get_linux_version(release_str) -> tuple[int, int, int]: ... HAVE_SIGNAL: bool EINTR_IS_EXPOSED: bool -LINUX_VERSION: Tuple[int, int, int] | None +LINUX_VERSION: tuple[int, int, int] | None _LOCALHOST: str _LOCALHOST_V6: str diff --git a/pika-stubs/connection.pyi b/pika-stubs/connection.pyi index f5297d3..fac8244 100644 --- a/pika-stubs/connection.pyi +++ b/pika-stubs/connection.pyi @@ -1,18 +1,18 @@ from __future__ import annotations import ssl -from typing import Any, Callable, Dict, Mapping, Type - +from collections.abc import Mapping +from typing import Any +from typing import Callable +from typing import Type from typing_extensions import Literal -from . import ( - callback, - channel as channel_, - compat, - credentials as credentials_, - frame, - spec, -) +from . import callback +from . import channel as channel_ +from . import compat +from . import credentials as credentials_ +from . import frame +from . import spec PRODUCT: str @@ -178,7 +178,7 @@ class Connection(compat.AbstractBase): params: Parameters | None = ... callbacks: callback.CallbackManager = ... server_capabilities: Mapping[str, Any] | None = ... - server_properties: Dict[str, Any] | None = ... + server_properties: dict[str, Any] | None = ... known_hosts: str | None = ... bytes_sent: int = ... diff --git a/pika-stubs/credentials.pyi b/pika-stubs/credentials.pyi index 5385d5b..33e4b31 100644 --- a/pika-stubs/credentials.pyi +++ b/pika-stubs/credentials.pyi @@ -1,7 +1,8 @@ -from typing import Tuple, Type +from __future__ import annotations -from . import spec +from typing import Type +from . import spec class PlainCredentials: @@ -16,7 +17,7 @@ class PlainCredentials: def response_for( self, start: spec.Connection.Start, - ) -> Tuple[str | None, str | None]: ... + ) -> tuple[str | None, str | None]: ... def erase_credentials(self) -> None: ... @@ -30,7 +31,7 @@ class ExternalCredentials: def response_for( self, start: spec.Connection.Start, - ) -> Tuple[str | None, str | None]: ... + ) -> tuple[str | None, str | None]: ... def erase_credentials(self) -> None: ... diff --git a/pika-stubs/exceptions.pyi b/pika-stubs/exceptions.pyi index d0a6bd4..955ae24 100644 --- a/pika-stubs/exceptions.pyi +++ b/pika-stubs/exceptions.pyi @@ -1,7 +1,8 @@ -from typing import Sequence +from __future__ import annotations -from .adapters import blocking_connection +from collections.abc import Sequence +from .adapters import blocking_connection class AMQPError(Exception): ... diff --git a/pika-stubs/frame.pyi b/pika-stubs/frame.pyi index 14c77cd..d9b0bc1 100644 --- a/pika-stubs/frame.pyi +++ b/pika-stubs/frame.pyi @@ -1,6 +1,11 @@ -from typing import Any, Generic, Tuple, TypeVar +from __future__ import annotations -from . import amqp_object, spec +from typing import Any +from typing import Generic +from typing import TypeVar + +from . import amqp_object +from . import spec _Method = TypeVar('_Method', bound=amqp_object.Method) @@ -79,4 +84,4 @@ class ProtocolHeader(amqp_object.AMQPObject): def marshal(self) -> bytes: ... -def decode_frame(data_in: bytes) -> Tuple[int, Frame | None]: ... +def decode_frame(data_in: bytes) -> tuple[int, Frame | None]: ... diff --git a/pika-stubs/spec.pyi b/pika-stubs/spec.pyi index b4f6147..fcde45e 100644 --- a/pika-stubs/spec.pyi +++ b/pika-stubs/spec.pyi @@ -1,7 +1,8 @@ from __future__ import annotations -from typing import Any, List, Mapping, Type - +from collections.abc import Mapping +from typing import Any +from typing import Type from typing_extensions import Literal from . import amqp_object as amqp_object @@ -72,7 +73,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.Start: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class StartOk(amqp_object.Method): @@ -96,7 +97,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.StartOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Secure(amqp_object.Method): @@ -111,7 +112,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.Secure: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class SecureOk(amqp_object.Method): @@ -126,7 +127,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.SecureOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Tune(amqp_object.Method): @@ -143,7 +144,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.Tune: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class TuneOk(amqp_object.Method): @@ -165,7 +166,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.TuneOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Open(amqp_object.Method): @@ -187,7 +188,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.Open: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class OpenOk(amqp_object.Method): @@ -202,7 +203,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.OpenOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Close(amqp_object.Method): @@ -226,7 +227,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.Close: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class CloseOk(amqp_object.Method): @@ -237,7 +238,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.CloseOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Blocked(amqp_object.Method): @@ -252,7 +253,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.Blocked: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Unblocked(amqp_object.Method): @@ -263,7 +264,7 @@ class Connection(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Connection.Unblocked: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Channel(amqp_object.Class): @@ -284,7 +285,7 @@ class Channel(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Channel.Open: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class OpenOk(amqp_object.Method): @@ -299,7 +300,7 @@ class Channel(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Channel.OpenOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Flow(amqp_object.Method): @@ -314,7 +315,7 @@ class Channel(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Channel.Flow: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class FlowOk(amqp_object.Method): @@ -329,7 +330,7 @@ class Channel(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Channel.FlowOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Close(amqp_object.Method): @@ -353,7 +354,7 @@ class Channel(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Channel.Close: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class CloseOk(amqp_object.Method): @@ -364,7 +365,7 @@ class Channel(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Channel.CloseOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Access(amqp_object.Class): @@ -398,7 +399,7 @@ class Access(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Access.Request: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class RequestOk(amqp_object.Method): @@ -413,7 +414,7 @@ class Access(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Access.RequestOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Exchange(amqp_object.Class): @@ -453,7 +454,7 @@ class Exchange(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Exchange.Declare: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class DeclareOk(amqp_object.Method): @@ -464,7 +465,7 @@ class Exchange(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Exchange.DeclareOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Delete(amqp_object.Method): @@ -488,7 +489,7 @@ class Exchange(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Exchange.Delete: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class DeleteOk(amqp_object.Method): @@ -499,7 +500,7 @@ class Exchange(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Exchange.DeleteOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Bind(amqp_object.Method): @@ -527,7 +528,7 @@ class Exchange(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Exchange.Bind: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class BindOk(amqp_object.Method): @@ -538,7 +539,7 @@ class Exchange(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Exchange.BindOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Unbind(amqp_object.Method): @@ -566,7 +567,7 @@ class Exchange(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Exchange.Unbind: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class UnbindOk(amqp_object.Method): @@ -577,7 +578,7 @@ class Exchange(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Exchange.UnbindOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Queue(amqp_object.Class): @@ -615,7 +616,7 @@ class Queue(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Queue.Declare: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class DeclareOk(amqp_object.Method): @@ -637,7 +638,7 @@ class Queue(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Queue.DeclareOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Bind(amqp_object.Method): @@ -665,7 +666,7 @@ class Queue(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Queue.Bind: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class BindOk(amqp_object.Method): @@ -676,7 +677,7 @@ class Queue(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Queue.BindOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Purge(amqp_object.Method): @@ -698,7 +699,7 @@ class Queue(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Queue.Purge: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class PurgeOk(amqp_object.Method): @@ -713,7 +714,7 @@ class Queue(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Queue.PurgeOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Delete(amqp_object.Method): @@ -739,7 +740,7 @@ class Queue(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Queue.Delete: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class DeleteOk(amqp_object.Method): @@ -754,7 +755,7 @@ class Queue(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Queue.DeleteOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Unbind(amqp_object.Method): @@ -780,7 +781,7 @@ class Queue(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Queue.Unbind: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class UnbindOk(amqp_object.Method): @@ -791,7 +792,7 @@ class Queue(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Queue.UnbindOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Basic(amqp_object.Class): @@ -819,7 +820,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.Qos: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class QosOk(amqp_object.Method): @@ -830,7 +831,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.QosOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Consume(amqp_object.Method): @@ -862,7 +863,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.Consume: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class ConsumeOk(amqp_object.Method): @@ -877,7 +878,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.ConsumeOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Cancel(amqp_object.Method): @@ -893,7 +894,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.Cancel: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class CancelOk(amqp_object.Method): @@ -908,7 +909,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.CancelOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Publish(amqp_object.Method): @@ -934,7 +935,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.Publish: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Return(amqp_object.Method): @@ -958,7 +959,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.Return: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Deliver(amqp_object.Method): @@ -984,7 +985,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.Deliver: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Get(amqp_object.Method): @@ -1006,7 +1007,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.Get: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class GetOk(amqp_object.Method): @@ -1032,7 +1033,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.GetOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class GetEmpty(amqp_object.Method): @@ -1047,7 +1048,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.GetEmpty: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Ack(amqp_object.Method): @@ -1063,7 +1064,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.Ack: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Reject(amqp_object.Method): @@ -1079,7 +1080,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.Reject: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class RecoverAsync(amqp_object.Method): @@ -1094,7 +1095,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.RecoverAsync: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Recover(amqp_object.Method): @@ -1109,7 +1110,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.Recover: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class RecoverOk(amqp_object.Method): @@ -1120,7 +1121,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.RecoverOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Nack(amqp_object.Method): @@ -1142,7 +1143,7 @@ class Basic(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Basic.Nack: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Tx(amqp_object.Class): @@ -1159,7 +1160,7 @@ class Tx(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Tx.Select: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class SelectOk(amqp_object.Method): @@ -1170,7 +1171,7 @@ class Tx(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Tx.SelectOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Commit(amqp_object.Method): @@ -1181,7 +1182,7 @@ class Tx(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Tx.Commit: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class CommitOk(amqp_object.Method): @@ -1192,7 +1193,7 @@ class Tx(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Tx.CommitOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Rollback(amqp_object.Method): @@ -1203,7 +1204,7 @@ class Tx(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Tx.Rollback: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class RollbackOk(amqp_object.Method): @@ -1214,7 +1215,7 @@ class Tx(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Tx.RollbackOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class Confirm(amqp_object.Class): @@ -1235,7 +1236,7 @@ class Confirm(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Confirm.Select: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class SelectOk(amqp_object.Method): @@ -1246,7 +1247,7 @@ class Confirm(amqp_object.Class): def synchronous(self) -> bool: ... def decode(self, encoded: bytes, offset: int = ...) -> Confirm.SelectOk: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... class BasicProperties(amqp_object.Properties): @@ -1305,7 +1306,7 @@ class BasicProperties(amqp_object.Properties): ) -> None: ... def decode(self, encoded: bytes, offset: int = ...) -> BasicProperties: ... - def encode(self) -> List[bytes]: ... + def encode(self) -> list[bytes]: ... methods: Mapping[int, amqp_object.Method] From 1f07eba70343adcdc6e56c88c155af9592154512 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Mon, 17 Jan 2022 15:30:29 -0600 Subject: [PATCH 08/11] formatting --- pika-stubs/__init__.pyi | 12 +- pika-stubs/adapters/__init__.pyi | 7 +- pika-stubs/adapters/asyncio_connection.pyi | 17 +- pika-stubs/adapters/base_connection.pyi | 20 +- pika-stubs/adapters/blocking_connection.pyi | 165 +----- pika-stubs/adapters/select_connection.pyi | 68 +-- pika-stubs/adapters/tornado_connection.pyi | 17 +- pika-stubs/adapters/twisted_connection.pyi | 115 +---- .../adapters/utils/connection_workflow.pyi | 81 +-- .../adapters/utils/io_services_utils.pyi | 12 +- pika-stubs/adapters/utils/nbio_interface.pyi | 35 +- .../utils/selector_ioloop_adapter.pyi | 33 +- pika-stubs/amqp_object.pyi | 6 - pika-stubs/callback.pyi | 22 +- pika-stubs/channel.pyi | 116 +---- pika-stubs/compat.pyi | 4 +- pika-stubs/connection.pyi | 40 +- pika-stubs/credentials.pyi | 17 +- pika-stubs/exceptions.pyi | 184 ++----- pika-stubs/exchange_type.pyi | 1 - pika-stubs/frame.pyi | 29 +- pika-stubs/spec.pyi | 484 ++++-------------- 22 files changed, 262 insertions(+), 1223 deletions(-) diff --git a/pika-stubs/__init__.pyi b/pika-stubs/__init__.pyi index 628dba4..e1bf725 100644 --- a/pika-stubs/__init__.pyi +++ b/pika-stubs/__init__.pyi @@ -1,12 +1,10 @@ -from .connection import ConnectionParameters as ConnectionParameters -from .connection import SSLOptions as SSLOptions -from .connection import URLParameters as URLParameters -from .credentials import PlainCredentials as PlainCredentials -from .spec import BasicProperties as BasicProperties - from . import adapters from .adapters import BaseConnection as BaseConnection from .adapters import BlockingConnection as BlockingConnection from .adapters import SelectConnection as SelectConnection - from .adapters.utils.connection_workflow import AMQPConnectionWorkflow as AMQPConnectionWorkflow +from .connection import ConnectionParameters as ConnectionParameters +from .connection import SSLOptions as SSLOptions +from .connection import URLParameters as URLParameters +from .credentials import PlainCredentials as PlainCredentials +from .spec import BasicProperties as BasicProperties diff --git a/pika-stubs/adapters/__init__.pyi b/pika-stubs/adapters/__init__.pyi index bd64ca1..1cb978e 100644 --- a/pika-stubs/adapters/__init__.pyi +++ b/pika-stubs/adapters/__init__.pyi @@ -1,3 +1,4 @@ -from .base_connection import BaseConnection as BaseConnection # noqa: F401 -from .blocking_connection import BlockingConnection as BlockingConnection # noqa: F401 -from .select_connection import IOLoop as IOLoop, SelectConnection as SelectConnection # noqa: F401 +from .base_connection import BaseConnection as BaseConnection +from .blocking_connection import BlockingConnection as BlockingConnection +from .select_connection import IOLoop as IOLoop +from .select_connection import SelectConnection as SelectConnection diff --git a/pika-stubs/adapters/asyncio_connection.pyi b/pika-stubs/adapters/asyncio_connection.pyi index 2fed447..0bf2587 100644 --- a/pika-stubs/adapters/asyncio_connection.pyi +++ b/pika-stubs/adapters/asyncio_connection.pyi @@ -8,13 +8,11 @@ from .. import connection from . import base_connection from .utils import connection_workflow -_OnCloseCallback = Callable[['AsyncioConnection', Exception], None] -_OnOpenCallback = Callable[['AsyncioConnection'], None] -_OnOpenErrorCallback = Callable[['AsyncioConnection', str | Exception], None] - +_OnCloseCallback = Callable[["AsyncioConnection", Exception], None] +_OnOpenCallback = Callable[["AsyncioConnection"], None] +_OnOpenErrorCallback = Callable[["AsyncioConnection", str | Exception], None] class AsyncioConnection(base_connection.BaseConnection[asyncio.AbstractEventLoop]): - def __init__( self, parameters: connection.Parameters | None = ..., @@ -24,18 +22,17 @@ class AsyncioConnection(base_connection.BaseConnection[asyncio.AbstractEventLoop custom_ioloop: asyncio.AbstractEventLoop | None = ..., internal_connection_workflow: bool = ..., ) -> None: ... - @classmethod def create_connection( cls, connection_configs: Sequence[connection.Parameters], on_done: Callable[ [ - connection.Connection | - connection_workflow.AMQPConnectionWorkflowFailed | - connection_workflow.AMQPConnectionWorkflowAborted + connection.Connection + | connection_workflow.AMQPConnectionWorkflowFailed + | connection_workflow.AMQPConnectionWorkflowAborted ], - None + None, ], custom_ioloop: asyncio.AbstractEventLoop | None = ..., workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = ..., diff --git a/pika-stubs/adapters/base_connection.pyi b/pika-stubs/adapters/base_connection.pyi index 5410793..586218e 100644 --- a/pika-stubs/adapters/base_connection.pyi +++ b/pika-stubs/adapters/base_connection.pyi @@ -10,15 +10,13 @@ from .. import connection from .utils import connection_workflow from .utils import nbio_interface -_OnCloseCallback = Callable[['BaseConnection', Exception], None] -_OnOpenCallback = Callable[['BaseConnection'], None] -_OnOpenErrorCallback = Callable[['BaseConnection', str | Exception], None] - -_IOLoop = TypeVar('_IOLoop') +_OnCloseCallback = Callable[["BaseConnection", Exception], None] +_OnOpenCallback = Callable[["BaseConnection"], None] +_OnOpenErrorCallback = Callable[["BaseConnection", str | Exception], None] +_IOLoop = TypeVar("_IOLoop") class BaseConnection(Generic[_IOLoop], connection.Connection): - def __init__( self, parameters: connection.Parameters | None, @@ -28,7 +26,6 @@ class BaseConnection(Generic[_IOLoop], connection.Connection): nbio: nbio_interface.AbstractIOServices, internal_connection_workflow: bool, ) -> None: ... - @classmethod @abc.abstractmethod def create_connection( @@ -36,15 +33,14 @@ class BaseConnection(Generic[_IOLoop], connection.Connection): connection_configs: Sequence[connection.Parameters], on_done: Callable[ [ - connection.Connection | - connection_workflow.AMQPConnectionWorkflowFailed | - connection_workflow.AMQPConnectionWorkflowAborted, + connection.Connection + | connection_workflow.AMQPConnectionWorkflowFailed + | connection_workflow.AMQPConnectionWorkflowAborted ], - None + None, ], custom_ioloop: _IOLoop | None = ..., workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = ..., ) -> connection_workflow.AbstractAMQPConnectionWorkflow: ... - @property def ioloop(self) -> _IOLoop: ... diff --git a/pika-stubs/adapters/blocking_connection.pyi b/pika-stubs/adapters/blocking_connection.pyi index 066a791..9499b05 100644 --- a/pika-stubs/adapters/blocking_connection.pyi +++ b/pika-stubs/adapters/blocking_connection.pyi @@ -16,45 +16,22 @@ from .. import spec from ..exchange_type import ExchangeType class BlockingConnection: - def __init__( - self, - parameters: connection.Parameters | Sequence[connection.Parameters] | None = ..., - _impl_class: Any | None = ..., + self, parameters: connection.Parameters | Sequence[connection.Parameters] | None = ..., _impl_class: Any | None = ... ) -> None: ... - def __enter__(self) -> BlockingConnection: ... - def __exit__( - self, - exc_type: Type[BaseException] | None, - value: BaseException | None, - traceback: types.TracebackType | None, - ) -> None: ... - - def add_on_connection_blocked_callback( - self, - callback: Callable[[spec.Connection.Blocked], None], - ) -> None: ... - - def add_on_connection_unblocked_callback( - self, - callback: Callable[[spec.Connection.Unblocked], None], + self, exc_type: Type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None ) -> None: ... - - def call_later( - self, - delay: float, - callback: Callable[[], None], - ) -> object: ... - + def add_on_connection_blocked_callback(self, callback: Callable[[spec.Connection.Blocked], None]) -> None: ... + def add_on_connection_unblocked_callback(self, callback: Callable[[spec.Connection.Unblocked], None]) -> None: ... + def call_later(self, delay: float, callback: Callable[[], None]) -> object: ... def add_callback_threadsafe(self, callback: Callable[[], None]) -> None: ... def remove_timeout(self, timeout_id: object) -> None: ... def close(self, reply_code: int = ..., reply_text: str = ...) -> None: ... def process_data_events(self, time_limit: int = ...) -> None: ... def sleep(self, duration: float) -> None: ... def channel(self, channel_number: int | None = ...) -> BlockingChannel: ... - @property def is_closed(self) -> bool: ... @property @@ -67,7 +44,6 @@ class BlockingConnection: def exchange_exchange_bindings_supported(self) -> bool: ... @property def publisher_confirms_supported(self) -> bool: ... - # Legacy property names for backward compatibility @property def basic_nack(self) -> bool: ... @@ -78,36 +54,20 @@ class BlockingConnection: @property def publisher_confirms(self) -> bool: ... - class ReturnedMessage: method: spec.Basic.Return = ... properties: spec.BasicProperties = ... body: bytes = ... - - def __init__( - self, - method: spec.Basic.Return, - properties: spec.BasicProperties, - body: bytes, - ) -> None: ... - + def __init__(self, method: spec.Basic.Return, properties: spec.BasicProperties, body: bytes) -> None: ... class BlockingChannel: - def __init__(self, channel_impl: channel.Channel, connection: BlockingConnection) -> None: ... - def __int__(self) -> int: ... - def __enter__(self) -> BlockingChannel: ... - def __exit__( - self, - exc_type: Type[BaseException] | None, - value: BaseException | None, - traceback: types.TracebackType | None, + self, exc_type: Type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None ) -> None: ... - @property def channel_number(self) -> int: ... @property @@ -118,37 +78,22 @@ class BlockingChannel: def is_open(self) -> bool: ... @property def consumer_tags(self) -> list[str]: ... - def close(self, reply_code: int = ..., reply_text: str = ...) -> None: ... def flow(self, active: bool) -> bool: ... - def add_on_cancel_callback(self, callback: Callable[[spec.Basic.Cancel], None]) -> None: ... def add_on_return_callback(self, callback: Callable[[spec.Basic.Return], None]) -> None: ... - def basic_consume( self, queue: Any, - on_message_callback: Callable[ - [ - BlockingChannel, - spec.Basic.Deliver, - spec.BasicProperties, - bytes, - ], - None, - ], + on_message_callback: Callable[[BlockingChannel, spec.Basic.Deliver, spec.BasicProperties, bytes], None], auto_ack: bool = ..., exclusive: bool = ..., consumer_tag: str | None = ..., arguments: Mapping[str, Any] | None = ..., ) -> str: ... - - def basic_cancel(self, consumer_tag: str) -> list[ - tuple[spec.Basic.Deliver, spec.BasicProperties, bytes], - ]: ... + def basic_cancel(self, consumer_tag: str) -> list[tuple[spec.Basic.Deliver, spec.BasicProperties, bytes]]: ... def start_consuming(self) -> None: ... def stop_consuming(self, consumer_tag: str | None = ...) -> None: ... - def consume( self, queue: str, @@ -156,59 +101,21 @@ class BlockingChannel: exclusive: bool = ..., arguments: Mapping[str, Any] | None = ..., inactivity_timeout: float | None = ..., - ) -> Iterator[ - tuple[ - spec.Basic.Deliver, - spec.BasicProperties, - bytes, - ] | - tuple[ - None, - None, - None, - ], - ]: ... - + ) -> Iterator[tuple[spec.Basic.Deliver, spec.BasicProperties, bytes] | tuple[None, None, None]]: ... def get_waiting_message_count(self) -> int: ... - def cancel(self) -> int: ... - def basic_ack(self, delivery_tag: int = ..., multiple: bool = ...) -> None: ... - - def basic_nack( - self, - delivery_tag: int | None = ..., - multiple: bool = ..., - requeue: bool = ..., - ) -> None: ... - - def basic_get(self, queue: str, auto_ack: bool = ...) -> tuple[ - spec.Basic.GetOk | None, - spec.BasicProperties | None, - str | None, - ]: ... - + def basic_nack(self, delivery_tag: int | None = ..., multiple: bool = ..., requeue: bool = ...) -> None: ... + def basic_get( + self, queue: str, auto_ack: bool = ... + ) -> tuple[spec.Basic.GetOk | None, spec.BasicProperties | None, str | None]: ... def basic_publish( - self, - exchange: str, - routing_key: str, - body: AnyStr, - properties: spec.BasicProperties | None = ..., - mandatory: bool = ..., - ) -> None: ... - - def basic_qos( - self, - prefetch_size: int = ..., - prefetch_count: int = ..., - global_qos: bool = ..., + self, exchange: str, routing_key: str, body: AnyStr, properties: spec.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 | None = ..., requeue: bool = ...) -> None: ... - def confirm_delivery(self) -> None: ... - def exchange_declare( self, exchange: str, @@ -219,21 +126,10 @@ class BlockingChannel: internal: bool = ..., arguments: Mapping[str, Any] | None = ..., ) -> frame.Method[spec.Exchange.DeclareOk]: ... - - def exchange_delete( - self, - exchange: str | None = ..., - if_unused: bool = ..., - ) -> frame.Method[spec.Exchange.DeleteOk]: ... - + def exchange_delete(self, exchange: str | None = ..., if_unused: bool = ...) -> frame.Method[spec.Exchange.DeleteOk]: ... def exchange_bind( - self, - destination: str, - source: str, - routing_key: str = ..., - arguments: Mapping[str, Any] | None = ..., + self, destination: str, source: str, routing_key: str = ..., arguments: Mapping[str, Any] | None = ... ) -> frame.Method[spec.Exchange.BindOk]: ... - def exchange_unbind( self, destination: str | None = ..., @@ -241,7 +137,6 @@ class BlockingChannel: routing_key: str = ..., arguments: Mapping[str, Any] | None = ..., ) -> frame.Method[spec.Exchange.UnbindOk]: ... - def queue_declare( self, queue: str, @@ -251,32 +146,14 @@ class BlockingChannel: auto_delete: bool = ..., arguments: Mapping[str, Any] | None = ..., ) -> frame.Method[spec.Queue.DeclareOk]: ... - - def queue_delete( - self, - queue: str, - if_unused: bool = ..., - if_empty: bool = ..., - ) -> frame.Method[spec.Queue.DeleteOk]: ... - + def queue_delete(self, queue: str, if_unused: bool = ..., if_empty: bool = ...) -> frame.Method[spec.Queue.DeleteOk]: ... def queue_purge(self, queue: str) -> frame.Method[spec.Queue.PurgeOk]: ... - def queue_bind( - self, - queue: str, - exchange: str, - routing_key: str | None = ..., - arguments: Mapping[str, Any] | None = ..., + self, queue: str, exchange: str, routing_key: str | None = ..., arguments: Mapping[str, Any] | None = ... ) -> frame.Method[spec.Queue.BindOk]: ... - def queue_unbind( - self, - queue: Any, - exchange: str | None = ..., - routing_key: str | None = ..., - arguments: Mapping[str, Any] | None = ..., + self, queue: Any, exchange: str | None = ..., routing_key: str | None = ..., arguments: Mapping[str, Any] | None = ... ) -> frame.Method[spec.Queue.UnbindOk]: ... - def tx_select(self) -> frame.Method[spec.Tx.SelectOk]: ... def tx_commit(self) -> frame.Method[spec.Tx.CommitOk]: ... def tx_rollback(self) -> frame.Method[spec.Tx.CommitOk]: ... diff --git a/pika-stubs/adapters/select_connection.pyi b/pika-stubs/adapters/select_connection.pyi index a8d78df..f7cb33d 100644 --- a/pika-stubs/adapters/select_connection.pyi +++ b/pika-stubs/adapters/select_connection.pyi @@ -20,9 +20,7 @@ _OnCloseCallback = Callable[[base_connection.BaseConnection, Exception], None] _OnOpenCallback = Callable[[base_connection.BaseConnection], None] _OnOpenErrorCallback = Callable[[base_connection.BaseConnection, str | Exception], None] - -class SelectConnection(base_connection.BaseConnection['IOLoop']): - +class SelectConnection(base_connection.BaseConnection["IOLoop"]): def __init__( self, parameters: connection.Parameters | None = ..., @@ -32,31 +30,27 @@ class SelectConnection(base_connection.BaseConnection['IOLoop']): custom_ioloop: IOLoop | nbio_interface.AbstractIOServices | None = ..., internal_connection_workflow: bool = ..., ) -> None: ... - @classmethod def create_connection( cls, connection_configs: Sequence[connection.Parameters], on_done: Callable[ [ - connection.Connection | - connection_workflow.AMQPConnectionWorkflowFailed | - connection_workflow.AMQPConnectionWorkflowAborted + connection.Connection + | connection_workflow.AMQPConnectionWorkflowFailed + | connection_workflow.AMQPConnectionWorkflowAborted ], - None + None, ], custom_ioloop: IOLoop | None = ..., workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = ..., ) -> connection_workflow.AbstractAMQPConnectionWorkflow: ... - class _Timeout: deadline: float = ... callback: Callable[[], None] = ... - def __init__(self, deadline: float, callback: Callable[[], None]) -> None: ... - def __eq__(self, other: Any) -> bool: ... def __ne__(self, other: Any) -> bool: ... def __lt__(self, other: Any) -> bool: ... @@ -64,20 +58,17 @@ class _Timeout: def __le__(self, other: Any) -> bool: ... def __ge__(self, other: Any) -> bool: ... - class PollEvents: READ: int = ... WRITE: int = ... ERROR: int = ... - class IOLoop(selector_ioloop_adapter.AbstractSelectorIOLoop[_Timeout]): READ: int = ... WRITE: int = ... ERROR: int = ... - def __init__(self) -> None: ... def close(self) -> None: ... def call_later(self, delay: float, callback: Callable[[], None]) -> _Timeout: ... @@ -85,14 +76,7 @@ class IOLoop(selector_ioloop_adapter.AbstractSelectorIOLoop[_Timeout]): def add_callback_threadsafe(self, callback: Callable[[], None]) -> None: ... def add_callback(self, callback: Callable[[], None]) -> None: ... def process_timeouts(self) -> None: ... - - def add_handler( - self, - fd: IO[AnyStr], - handler: Callable[[IO[AnyStr], int], None], - events: int, - ) -> None: ... - + def add_handler(self, fd: IO[AnyStr], handler: Callable[[IO[AnyStr], int], None], events: int) -> None: ... def update_handler(self, fd: IO[AnyStr], events: int) -> None: ... def remove_handler(self, fd: IO[AnyStr]) -> None: ... def start(self) -> None: ... @@ -101,69 +85,37 @@ class IOLoop(selector_ioloop_adapter.AbstractSelectorIOLoop[_Timeout]): def deactivate_poller(self) -> None: ... def poll(self) -> None: ... - class _PollerBase(compat.AbstractBase): POLL_TIMEOUT_MULT: int = ... - - def __init__( - self, - get_wait_seconds: Callable[[], float], - process_timeouts: Callable[[], None], - ) -> None: ... - + def __init__(self, get_wait_seconds: Callable[[], float], process_timeouts: Callable[[], None]) -> None: ... def close(self) -> None: ... def wake_threadsafe(self) -> None: ... - - def add_handler( - self, - fileno: int, - handler: Callable[[int, int], None], - events: int, - ) -> None: ... - + def add_handler(self, fileno: int, handler: Callable[[int, int], None], events: int) -> None: ... def update_handler(self, fileno: int, events: int) -> None: ... def remove_handler(self, fileno: int) -> None: ... def activate_poller(self) -> None: ... def deactivate_poller(self) -> None: ... def start(self) -> None: ... def stop(self) -> None: ... - @abc.abstractmethod def poll(self) -> None: ... - class SelectPoller(_PollerBase): POLL_TIMEOUT_MULT: int = ... - def poll(self) -> None: ... - class KQueuePoller(_PollerBase): - - def __init__( - self, - get_wait_seconds: Callable[[], float], - process_timeouts: Callable[[], None], - ) -> None: ... - + def __init__(self, get_wait_seconds: Callable[[], float], process_timeouts: Callable[[], None]) -> None: ... def poll(self) -> None: ... - class PollPoller(_PollerBase): POLL_TIMEOUT_MULT: int = ... - - def __init__( - self, - get_wait_seconds: Callable[[], float], - process_timeouts: Callable[[], None], - ) -> None: ... - + def __init__(self, get_wait_seconds: Callable[[], float], process_timeouts: Callable[[], None]) -> None: ... def poll(self) -> None: ... - class EPollPoller(PollPoller): POLL_TIMEOUT_MULT: int = ... diff --git a/pika-stubs/adapters/tornado_connection.pyi b/pika-stubs/adapters/tornado_connection.pyi index a90027b..73be212 100644 --- a/pika-stubs/adapters/tornado_connection.pyi +++ b/pika-stubs/adapters/tornado_connection.pyi @@ -10,13 +10,11 @@ from . import base_connection from .utils import connection_workflow from .utils import nbio_interface -_OnCloseCallback = Callable[['TornadoConnection', Exception], None] -_OnOpenCallback = Callable[['TornadoConnection'], None] -_OnOpenErrorCallback = Callable[['TornadoConnection', str | Exception], None] - +_OnCloseCallback = Callable[["TornadoConnection", Exception], None] +_OnOpenCallback = Callable[["TornadoConnection"], None] +_OnOpenErrorCallback = Callable[["TornadoConnection", str | Exception], None] class TornadoConnection(base_connection.BaseConnection[tornado.ioloop.IOLoop]): - def __init__( self, parameters: connection.Parameters | None = ..., @@ -26,18 +24,17 @@ class TornadoConnection(base_connection.BaseConnection[tornado.ioloop.IOLoop]): custom_ioloop: tornado.ioloop.IOLoop | nbio_interface.AbstractIOServices | None = ..., internal_connection_workflow: bool = ..., ) -> None: ... - @classmethod def create_connection( cls, connection_configs: Sequence[connection.Parameters], on_done: Callable[ [ - connection.Connection | - connection_workflow.AMQPConnectionWorkflowFailed | - connection_workflow.AMQPConnectionWorkflowAborted + connection.Connection + | connection_workflow.AMQPConnectionWorkflowFailed + | connection_workflow.AMQPConnectionWorkflowAborted ], - None + None, ], custom_ioloop: tornado.ioloop.IOLoop | None = ..., workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = ..., diff --git a/pika-stubs/adapters/twisted_connection.pyi b/pika-stubs/adapters/twisted_connection.pyi index bcbd5f4..8e80a3d 100644 --- a/pika-stubs/adapters/twisted_connection.pyi +++ b/pika-stubs/adapters/twisted_connection.pyi @@ -29,18 +29,11 @@ _T = TypeVar("_T") class ClosableDeferredQueue(DeferredQueue[_T]): closed: twisted.python.failure.Failure | Exception = ... - - def __init__( - self, - size: int | None = ..., - backlog: int | None = ..., - ) -> None: ... - + def __init__(self, size: int | None = ..., backlog: int | None = ...) -> None: ... def put(self, obj: _T) -> None: ... def get(self) -> Deferred[_T]: ... def close(self, reason: twisted.python.failure.Failure | Exception | str) -> None: ... - # Generic [named] tuples aren't supported (https://github.com/python/mypy/issues/685) # so we can't provide more specific type hints for `method` class ReceivedMessage(NamedTuple): @@ -49,40 +42,28 @@ class ReceivedMessage(NamedTuple): properties: spec.BasicProperties body: bytes - class TwistedChannel: on_closed: Deferred[twisted.python.failure.Failure | Exception | str] - def __init__(self, channel: Channel) -> None: ... - @property def channel_number(self) -> int: ... @property def connection(self) -> Connection: ... - @property def is_closed(self) -> bool: ... @property def is_closing(self) -> bool: ... @property def is_open(self) -> bool: ... - @property def flow_active(self) -> bool: ... @property def consumer_tags(self) -> list[str]: ... - - def callback_deferred( - self, - deferred: Deferred[Any], - replies: Sequence[Any], - ) -> None: ... - + def callback_deferred(self, deferred: Deferred[Any], replies: Sequence[Any]) -> None: ... # ReceivedMessage.method: spec.Basic.Return def add_on_return_callback(self, callback: Callable[[ReceivedMessage], None]) -> None: ... def basic_ack(self, delivery_tag: int = ..., multiple: bool = ...) -> None: ... def basic_cancel(self, consumer_tag: str = ...) -> None: ... - # ReceivedMessage.method: spec.Basic.Deliver def basic_consume( self, @@ -92,53 +73,22 @@ class TwistedChannel: consumer_tag: str | None = ..., arguments: Mapping[str, Any] | None = ..., ) -> Deferred[tuple[ClosableDeferredQueue[ReceivedMessage], str]]: ... - # ReceivedMessage.method: spec.Basic.GetOk - def basic_get( - self, - queue: str, - auto_ack: bool = ..., - ) -> Deferred[ReceivedMessage]: ... - - def basic_nack( - self, - delivery_tag: int | None = ..., - multiple: bool = ..., - requeue: bool = ..., - ) -> None: ... - + def basic_get(self, queue: str, auto_ack: bool = ...) -> Deferred[ReceivedMessage]: ... + def basic_nack(self, delivery_tag: int | None = ..., multiple: bool = ..., requeue: bool = ...) -> None: ... def basic_publish( - self, - exchange: str, - routing_key: str, - body: AnyStr, - properties: spec.BasicProperties | None = ..., - mandatory: bool = ..., + self, exchange: str, routing_key: str, body: AnyStr, properties: spec.BasicProperties | None = ..., mandatory: bool = ... ) -> Deferred[None]: ... - def basic_qos( - self, - prefetch_size: int = ..., - prefetch_count: int = ..., - global_qos: bool = ..., + self, prefetch_size: int = ..., prefetch_count: int = ..., global_qos: bool = ... ) -> Deferred[frame.Method[spec.Basic.QosOk]]: ... - def basic_reject(self, delivery_tag: int, requeue: bool = ...) -> None: ... - def basic_recover( - self, requeue: bool = ... - ) -> Deferred[frame.Method[spec.Basic.RecoverOk]]: ... - + def basic_recover(self, requeue: bool = ...) -> Deferred[frame.Method[spec.Basic.RecoverOk]]: ... def close(self, reply_code: int = ..., reply_text: str = ...) -> None: ... def confirm_delivery(self) -> Deferred[frame.Method[spec.Confirm.SelectOk]]: ... - def exchange_bind( - self, - destination: str, - source: str, - routing_key: str = ..., - arguments: Mapping[str, Any] | None = ..., + self, destination: str, source: str, routing_key: str = ..., arguments: Mapping[str, Any] | None = ... ) -> Deferred[frame.Method[spec.Exchange.BindOk]]: ... - def exchange_declare( self, exchange: str, @@ -149,13 +99,9 @@ class TwistedChannel: internal: bool = ..., arguments: Mapping[str, Any] | None = ..., ) -> Deferred[frame.Method[spec.Exchange.DeclareOk]]: ... - def exchange_delete( - self, - exchange: str | None = ..., - if_unused: bool = ..., + self, exchange: str | None = ..., if_unused: bool = ... ) -> Deferred[frame.Method[spec.Exchange.DeleteOk]]: ... - def exchange_unbind( self, destination: str | None = ..., @@ -163,18 +109,11 @@ class TwistedChannel: routing_key: str = ..., arguments: Mapping[str, Any] | None = ..., ) -> Deferred[frame.Method[spec.Exchange.UnbindOk]]: ... - def flow(self, active: bool) -> Deferred[frame.Method[spec.Channel.FlowOk]]: ... def open(self) -> None: ... - def queue_bind( - self, - queue: str, - exchange: str, - routing_key: str | None = ..., - arguments: Mapping[str, Any] | None = ..., + self, queue: str, exchange: str, routing_key: str | None = ..., arguments: Mapping[str, Any] | None = ... ) -> Deferred[frame.Method[spec.Queue.BindOk]]: ... - def queue_declare( self, queue: str, @@ -184,59 +123,33 @@ class TwistedChannel: auto_delete: bool = ..., arguments: Mapping[str, Any] | None = ..., ) -> Deferred[frame.Method[spec.Queue.DeclareOk]]: ... - def queue_delete( - self, - queue: str, - if_unused: bool = ..., - if_empty: bool = ..., + self, queue: str, if_unused: bool = ..., if_empty: bool = ... ) -> Deferred[frame.Method[spec.Queue.DeleteOk]]: ... - def queue_purge(self, queue: str) -> Deferred[frame.Method[spec.Queue.PurgeOk]]: ... - def queue_unbind( - self, - queue: str, - exchange: str | None = ..., - routing_key: str | None = ..., - arguments: Mapping[str, Any] | None = ..., + self, queue: str, exchange: str | None = ..., routing_key: str | None = ..., arguments: Mapping[str, Any] | None = ... ) -> Deferred[frame.Method[spec.Queue.UnbindOk]]: ... - def tx_commit(self) -> Deferred[frame.Method[spec.Tx.CommitOk]]: ... def tx_rollback(self) -> Deferred[frame.Method[spec.Tx.RollbackOk]]: ... def tx_select(self) -> Deferred[frame.Method[spec.Tx.SelectOk]]: ... - class TwistedProtocolConnection(twisted.internet.protocol.Protocol): ready: Deferred[TwistedProtocolConnection] = ... closed: Deferred[twisted.python.failure.Failure | Exception] | None = ... - def __init__( - self, - parameters: Parameters | None = ..., - custom_reactor: twisted.internet.base.ReactorBase | None = ..., + self, parameters: Parameters | None = ..., custom_reactor: twisted.internet.base.ReactorBase | None = ... ) -> None: ... - def channel(self, channel_number: int | None = ...) -> Deferred[TwistedChannel]: ... - @property def is_open(self) -> bool: ... @property def is_closed(self) -> bool: ... - - def close( - self, - reply_code: int = ..., - reply_text: str = ..., - ) -> Deferred[Exception]: ... - + def close(self, reply_code: int = ..., reply_text: str = ...) -> Deferred[Exception]: ... # IProtocol methods - def dataReceived(self, data: bytes) -> None: ... def connectionLost(self, reason: twisted.python.failure.Failure = ...) -> None: ... def makeConnection(self, transport: twisted.internet.interfaces.ITransport) -> None: ... - # Our own methods - def connectionReady(self) -> TwistedProtocolConnection: ... diff --git a/pika-stubs/adapters/utils/connection_workflow.pyi b/pika-stubs/adapters/utils/connection_workflow.pyi index 726ad5b..297b8f8 100644 --- a/pika-stubs/adapters/utils/connection_workflow.pyi +++ b/pika-stubs/adapters/utils/connection_workflow.pyi @@ -1,105 +1,54 @@ -from typing import Any, Callable +from typing import Any +from typing import Callable -from ... import compat, connection +from ... import compat +from ... import connection from . import nbio_interface - -class AMQPConnectorException(Exception): - ... - - -class AMQPConnectorStackTimeout(AMQPConnectorException): - ... - - -class AMQPConnectorAborted(AMQPConnectorException): - ... - - -class AMQPConnectorWrongState(AMQPConnectorException): - ... - +class AMQPConnectorException(Exception): ... +class AMQPConnectorStackTimeout(AMQPConnectorException): ... +class AMQPConnectorAborted(AMQPConnectorException): ... +class AMQPConnectorWrongState(AMQPConnectorException): ... class AMQPConnectorPhaseErrorBase(AMQPConnectorException): exception: Any = ... - def __init__(self, exception: Any, *args: Any) -> None: ... - -class AMQPConnectorSocketConnectError(AMQPConnectorPhaseErrorBase): - ... - - -class AMQPConnectorTransportSetupError(AMQPConnectorPhaseErrorBase): - ... - - -class AMQPConnectorAMQPHandshakeError(AMQPConnectorPhaseErrorBase): - ... - - -class AMQPConnectionWorkflowAborted(AMQPConnectorException): - ... - - -class AMQPConnectionWorkflowWrongState(AMQPConnectorException): - ... - +class AMQPConnectorSocketConnectError(AMQPConnectorPhaseErrorBase): ... +class AMQPConnectorTransportSetupError(AMQPConnectorPhaseErrorBase): ... +class AMQPConnectorAMQPHandshakeError(AMQPConnectorPhaseErrorBase): ... +class AMQPConnectionWorkflowAborted(AMQPConnectorException): ... +class AMQPConnectionWorkflowWrongState(AMQPConnectorException): ... class AMQPConnectionWorkflowFailed(AMQPConnectorException): exceptions: Any = ... - def __init__(self, exceptions: Any, *args: Any) -> None: ... - class AMQPConnector: - def __init__(self, conn_factory: Any, nbio: Any) -> None: ... def start(self, addr_record: Any, conn_params: Any, on_done: Any) -> None: ... def abort(self) -> None: ... - class AbstractAMQPConnectionWorkflow(compat.AbstractBase): - def start( self, connection_configs: connection.Parameters, connector_factory: Callable[[], AMQPConnector], native_loop: object, - on_done: Callable[ - [ - connection.Connection | - AMQPConnectionWorkflowFailed| - AMQPConnectionWorkflowAborted - ], - None - ], + on_done: Callable[[connection.Connection | AMQPConnectionWorkflowFailed | AMQPConnectionWorkflowAborted], None], ) -> None: ... - def abort(self) -> None: ... - class AMQPConnectionWorkflow(AbstractAMQPConnectionWorkflow): - def __init__(self, _until_first_amqp_attempt: bool = ...) -> None: ... - def set_io_services(self, nbio: nbio_interface.AbstractIOServices) -> None: ... - def start( self, connection_configs: connection.Parameters, connector_factory: Callable[[], AMQPConnector], native_loop: object, - on_done: Callable[ - [ - connection.Connection | - AMQPConnectionWorkflowFailed | - AMQPConnectionWorkflowAborted - ], - None - ], + on_done: Callable[[connection.Connection | AMQPConnectionWorkflowFailed | AMQPConnectionWorkflowAborted], None], ) -> None: ... - def abort(self) -> None: ... diff --git a/pika-stubs/adapters/utils/io_services_utils.pyi b/pika-stubs/adapters/utils/io_services_utils.pyi index df95ae5..dee3081 100644 --- a/pika-stubs/adapters/utils/io_services_utils.pyi +++ b/pika-stubs/adapters/utils/io_services_utils.pyi @@ -11,22 +11,18 @@ def check_callback_arg(callback: Callable, name: str) -> None: ... def check_fd_arg(fd: int) -> None: ... class SocketConnectionMixin: - def connect_socket( - self, - sock: socket, - resolved_addr: Any, - on_done: Callable[[BaseException | None], None], + self, sock: socket, resolved_addr: Any, on_done: Callable[[BaseException | None], None] ) -> nbio_interface.AbstractIOReference: ... - class StreamingConnectionMixin: - def create_streaming_connection( self, protocol_factory: Callable[[], nbio_interface.AbstractStreamProtocol], sock: socket, - on_done: Callable[[ BaseException | tuple[ nbio_interface.AbstractStreamTransport, nbio_interface.AbstractStreamProtocol]], None], + on_done: Callable[ + [BaseException | tuple[nbio_interface.AbstractStreamTransport, nbio_interface.AbstractStreamProtocol]], None + ], ssl_context: ssl.SSLContext | None = ..., server_hostname: str | None = ..., ) -> nbio_interface.AbstractIOReference: ... diff --git a/pika-stubs/adapters/utils/nbio_interface.pyi b/pika-stubs/adapters/utils/nbio_interface.pyi index 1f33927..f393c4d 100644 --- a/pika-stubs/adapters/utils/nbio_interface.pyi +++ b/pika-stubs/adapters/utils/nbio_interface.pyi @@ -14,7 +14,6 @@ from typing import Text from ... import compat class AbstractIOServices(compat.AbstractBase): - @abc.abstractmethod def get_native_ioloop(self) -> object: ... @abc.abstractmethod @@ -27,52 +26,32 @@ class AbstractIOServices(compat.AbstractBase): def add_callback_threadsafe(self, callback: Callable[[], None]) -> None: ... @abc.abstractmethod def call_later(self, delay: float, callback: Callable[[], None]) -> AbstractTimerReference: ... - @abc.abstractmethod def getaddrinfo( self, host: bytearray | bytes | Text | None, port: str | int | None, - on_done: Callable[ - [ - BaseException | - list[tuple[AddressFamily, SocketKind, int, str, tuple[Any, ...]]], - ], - None, - ], + on_done: Callable[[BaseException | list[tuple[AddressFamily, SocketKind, int, str, tuple[Any, ...]]]], None], family: int = ..., socktype: int = ..., proto: int = ..., flags: int = ..., ) -> AbstractIOReference: ... - @abc.abstractmethod def connect_socket( - self, - sock: socket, - resolved_addr: Any, - on_done: Callable[[BaseException | None], None], + self, sock: socket, resolved_addr: Any, on_done: Callable[[BaseException | None], None] ) -> AbstractIOReference: ... - @abc.abstractmethod def create_streaming_connection( self, protocol_factory: Callable[[], AbstractStreamProtocol], sock: socket, - on_done: Callable[ - [ - BaseException | - tuple[AbstractStreamTransport, AbstractStreamProtocol], - ], - None, - ], + on_done: Callable[[BaseException | tuple[AbstractStreamTransport, AbstractStreamProtocol]], None], ssl_context: ssl.SSLContext | None = ..., server_hostname: str | None = ..., ) -> AbstractIOReference: ... - class AbstractFileDescriptorServices(compat.AbstractBase): - @abc.abstractmethod def set_reader(self, fd: IO[AnyStr], on_readable: Callable[[], None]) -> None: ... @abc.abstractmethod @@ -82,21 +61,15 @@ class AbstractFileDescriptorServices(compat.AbstractBase): @abc.abstractmethod def remove_writer(self, fd: IO[AnyStr]) -> bool: ... - class AbstractTimerReference(compat.AbstractBase): - @abc.abstractmethod def cancel(self) -> None: ... - class AbstractIOReference(compat.AbstractBase): - @abc.abstractmethod def cancel(self) -> bool: ... - class AbstractStreamProtocol(compat.AbstractBase): - @abc.abstractmethod def connection_made(self, transport: AbstractStreamTransport) -> None: ... @abc.abstractmethod @@ -106,9 +79,7 @@ class AbstractStreamProtocol(compat.AbstractBase): @abc.abstractmethod def data_received(self, data: bytes) -> None: ... - class AbstractStreamTransport(compat.AbstractBase): - @abc.abstractmethod def abort(self) -> None: ... @abc.abstractmethod diff --git a/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi b/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi index ae0b50b..71b325c 100644 --- a/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi +++ b/pika-stubs/adapters/utils/selector_ioloop_adapter.pyi @@ -14,11 +14,9 @@ from typing import TypeVar from . import io_services_utils from . import nbio_interface -_Timeout = TypeVar('_Timeout', bound=object) - +_Timeout = TypeVar("_Timeout", bound=object) class AbstractSelectorIOLoop(Generic[_Timeout], metaclass=abc.ABCMeta): - @property @abc.abstractmethod def READ(self) -> int: ... @@ -28,7 +26,6 @@ class AbstractSelectorIOLoop(Generic[_Timeout], metaclass=abc.ABCMeta): @property @abc.abstractmethod def ERROR(self) -> int: ... - @abc.abstractmethod def close(self) -> None: ... @abc.abstractmethod @@ -41,21 +38,13 @@ class AbstractSelectorIOLoop(Generic[_Timeout], metaclass=abc.ABCMeta): def remove_timeout(self, timeout_handle: _Timeout) -> None: ... @abc.abstractmethod def add_callback(self, callback: Callable[[], None]) -> None: ... - @abc.abstractmethod - def add_handler( - self, - fd: IO[AnyStr], - handler: Callable[[IO[AnyStr], int], None], - events: int, - ) -> None: ... - + def add_handler(self, fd: IO[AnyStr], handler: Callable[[IO[AnyStr], int], None], events: int) -> None: ... @abc.abstractmethod def update_handler(self, fd: IO[AnyStr], events: int) -> None: ... @abc.abstractmethod def remove_handler(self, fd: IO[AnyStr]) -> None: ... - class SelectorIOServicesAdapter( Generic[_Timeout], io_services_utils.SocketConnectionMixin, @@ -63,37 +52,23 @@ class SelectorIOServicesAdapter( nbio_interface.AbstractIOServices, nbio_interface.AbstractFileDescriptorServices, ): - def __init__(self, native_loop: AbstractSelectorIOLoop[_Timeout]) -> None: ... def get_native_ioloop(self) -> AbstractSelectorIOLoop[_Timeout]: ... def close(self) -> None: ... def run(self) -> None: ... def stop(self) -> None: ... def add_callback_threadsafe(self, callback: Callable[[], None]) -> None: ... - - def call_later( - self, - delay: float, - callback: Callable[[], None], - ) -> nbio_interface.AbstractTimerReference: ... - + def call_later(self, delay: float, callback: Callable[[], None]) -> nbio_interface.AbstractTimerReference: ... def getaddrinfo( self, host: bytearray | bytes | Text | None, port: str | int | None, - on_done: Callable[ - [ - BaseException | - list[tuple[AddressFamily, SocketKind, int, str, tuple[Any, ...]]], - ], - None, - ], + on_done: Callable[[BaseException | list[tuple[AddressFamily, SocketKind, int, str, tuple[Any, ...]]]], None], family: int = ..., socktype: int = ..., proto: int = ..., flags: int = ..., ) -> nbio_interface.AbstractIOReference: ... - def set_reader(self, fd: IO[AnyStr], on_readable: Callable[[], None]) -> None: ... def remove_reader(self, fd: IO[AnyStr]) -> bool: ... def set_writer(self, fd: IO[AnyStr], on_writable: Callable[[], None]) -> None: ... diff --git a/pika-stubs/amqp_object.pyi b/pika-stubs/amqp_object.pyi index d59735d..1a221c1 100644 --- a/pika-stubs/amqp_object.pyi +++ b/pika-stubs/amqp_object.pyi @@ -1,28 +1,22 @@ from __future__ import annotations - class AMQPObject: NAME: str = ... INDEX: int | None = ... - class Class(AMQPObject): NAME: str = ... - class Method(AMQPObject): NAME: str = ... - @property def synchronous(self) -> bool: ... - def get_properties(self) -> Properties: ... def get_body(self) -> bytes: ... - class Properties(AMQPObject): NAME: str = ... diff --git a/pika-stubs/callback.pyi b/pika-stubs/callback.pyi index 33de281..562bf18 100644 --- a/pika-stubs/callback.pyi +++ b/pika-stubs/callback.pyi @@ -11,12 +11,10 @@ _Key = Any _Caller = object _Callback = Callable[..., Any] - def name_or_value(value: amqp_object.AMQPObject) -> str: ... def sanitize_prefix(function: _Callback) -> _Callback: ... def check_for_prefix_and_key(function: _Callback) -> _Callback: ... - class CallbackManager: CALLS: str = ... @@ -25,7 +23,6 @@ class CallbackManager: CALLBACK: str = ... ONE_SHOT: str = ... ONLY_CALLER: str = ... - def add( self, prefix: _Prefix, @@ -35,26 +32,11 @@ class CallbackManager: only_caller: _Caller | None = ..., arguments: Mapping[str, Any] | None = ..., ) -> tuple[_Prefix, Any]: ... - def clear(self) -> None: ... def cleanup(self, prefix: _Prefix) -> bool: ... - def pending(self, prefix: _Prefix, key: _Key) -> int | None: ... - - def process( - self, - prefix: _Prefix, - key: _Key, - caller: _Caller, - *args: Any, - **keywords: Any, - ) -> bool: ... - + def process(self, prefix: _Prefix, key: _Key, caller: _Caller, *args: Any, **keywords: Any) -> bool: ... def remove( - self, - prefix: _Prefix, - key: _Key, - callback_value: _Callback | None = ..., - arguments: Mapping[str, Any] | None = ..., + self, prefix: _Prefix, key: _Key, callback_value: _Callback | None = ..., arguments: Mapping[str, Any] | None = ... ) -> bool: ... def remove_all(self, prefix: _Prefix, key: _Key) -> None: ... diff --git a/pika-stubs/channel.pyi b/pika-stubs/channel.pyi index 81c017a..68c1628 100644 --- a/pika-stubs/channel.pyi +++ b/pika-stubs/channel.pyi @@ -18,29 +18,28 @@ MAX_CHANNELS: Literal[65535] # per AMQP 0.9.1 spec. _OnAckNackCallback = Callable[[frame.Method[spec.Basic.Ack | spec.Basic.Nack]], None] _OnConfirmDeliveryCallback = Callable[[frame.Method[spec.Confirm.SelectOk]], None] _OnBasicConsumeCallback = Callable[[frame.Method[spec.Basic.ConsumeOk]], None] -_OnBasicGetCallback = Callable[['Channel', spec.Basic.GetOk, spec.BasicProperties, bytes], None] +_OnBasicGetCallback = Callable[["Channel", spec.Basic.GetOk, spec.BasicProperties, bytes], None] _OnBasicRecoverCallback = Callable[[frame.Method[spec.Basic.RecoverOk]], None] _OnBasicQosCallback = Callable[[frame.Method[spec.Basic.QosOk]], None] _OnBasicCancelCallback = Callable[[frame.Method[spec.Basic.CancelOk]], None] -_OnCloseCallback = Callable[['Channel', Exception], None] +_OnCloseCallback = Callable[["Channel", Exception], None] _OnExchangeBindCallback = Callable[[frame.Method[spec.Exchange.BindOk]], None] _OnExchangeDeclareCallback = Callable[[frame.Method[spec.Exchange.DeclareOk]], None] _OnExchangeDeleteCallback = Callable[[frame.Method[spec.Exchange.DeleteOk]], None] _OnExchangeUnbindCallback = Callable[[frame.Method[spec.Exchange.UnbindOk]], None] _OnFlowCallback = Callable[[bool], None] -_OnMessageCallback = Callable[['Channel', spec.Basic.Deliver, spec.BasicProperties, bytes], None] -_OnOpenCallback = Callable[['Channel'], None] +_OnMessageCallback = Callable[["Channel", spec.Basic.Deliver, spec.BasicProperties, bytes], None] +_OnOpenCallback = Callable[["Channel"], None] _OnQueueBindCallback = Callable[[frame.Method[spec.Queue.BindOk]], None] _OnQueueDeclareCallback = Callable[[frame.Method[spec.Queue.DeclareOk]], None] _OnQueueDeleteCallback = Callable[[frame.Method[spec.Queue.DeleteOk]], None] _OnQueuePurgeCallback = Callable[[frame.Method[spec.Queue.PurgeOk]], None] _OnQueueUnbindCallback = Callable[[frame.Method[spec.Queue.UnbindOk]], None] -_OnReturnCallback = Callable[['Channel', spec.Basic.Return, spec.BasicProperties, bytes], None] +_OnReturnCallback = Callable[["Channel", spec.Basic.Return, spec.BasicProperties, bytes], None] _OnTxCommitCallback = Callable[[spec.Tx.CommitOk], None] _OnTxRollbackCallback = Callable[[spec.Tx.RollbackOk], None] _OnTxSelectCallback = Callable[[spec.Tx.SelectOk], None] - class Channel: CLOSED: int = ... OPENING: int = ... @@ -51,40 +50,15 @@ class Channel: callbacks: callback.CallbackManager = ... connection: connection_.Connection = ... flow_active: bool = ... - - def __init__( - self, - connection: connection_.Connection, - channel_number: int, - on_open_callback: _OnOpenCallback, - ) -> None: ... - + def __init__(self, connection: connection_.Connection, channel_number: int, on_open_callback: _OnOpenCallback) -> None: ... def __int__(self) -> int: ... - - def add_callback( - self, - callback: Callable[..., Any], - replies: Sequence[Any], - one_shot: bool = ..., - ) -> None: ... - + def add_callback(self, callback: Callable[..., Any], replies: Sequence[Any], one_shot: bool = ...) -> None: ... def add_on_cancel_callback(self, callback: _OnBasicCancelCallback) -> None: ... def add_on_close_callback(self, callback: _OnCloseCallback) -> None: ... def add_on_flow_callback(self, callback: _OnFlowCallback) -> None: ... def add_on_return_callback(self, callback: _OnReturnCallback) -> None: ... - - def basic_ack( - self, - delivery_tag: int = ..., - multiple: bool = ..., - ) -> None: ... - - def basic_cancel( - self, - consumer_tag: str = ..., - callback: _OnBasicCancelCallback | None = ..., - ) -> None: ... - + def basic_ack(self, delivery_tag: int = ..., multiple: bool = ...) -> None: ... + def basic_cancel(self, consumer_tag: str = ..., callback: _OnBasicCancelCallback | None = ...) -> None: ... def basic_consume( self, queue: str, @@ -95,30 +69,11 @@ class Channel: arguments: Mapping[str, Any] | None = ..., callback: _OnBasicConsumeCallback | None = ..., ) -> str: ... - - def basic_get( - self, - queue: str, - callback: _OnBasicGetCallback, - auto_ack: bool = ..., - ) -> None: ... - - def basic_nack( - self, - delivery_tag: int | None = ..., - multiple: bool = ..., - requeue: bool = ..., - ) -> None: ... - + def basic_get(self, queue: str, callback: _OnBasicGetCallback, auto_ack: bool = ...) -> None: ... + def basic_nack(self, delivery_tag: int | None = ..., multiple: bool = ..., requeue: bool = ...) -> None: ... def basic_publish( - self, - exchange: str, - routing_key: str, - body: AnyStr, - properties: spec.BasicProperties | None = ..., - mandatory: bool = ..., + self, exchange: str, routing_key: str, body: AnyStr, properties: spec.BasicProperties | None = ..., mandatory: bool = ... ) -> None: ... - def basic_qos( self, prefetch_size: int = ..., @@ -126,26 +81,14 @@ class Channel: global_qos: bool = ..., callback: _OnBasicQosCallback | None = ..., ) -> None: ... - def basic_reject(self, delivery_tag: int = ..., requeue: bool = ...) -> None: ... - - def basic_recover( - self, - requeue: bool = ..., - callback: _OnBasicRecoverCallback | None = ..., - ) -> None: ... - + def basic_recover(self, requeue: bool = ..., callback: _OnBasicRecoverCallback | None = ...) -> None: ... def close(self, reply_code: int = ..., reply_text: str = ...) -> None: ... - def confirm_delivery( - self, - ack_nack_callback: _OnAckNackCallback, - callback: _OnConfirmDeliveryCallback | None = ..., + self, ack_nack_callback: _OnAckNackCallback, callback: _OnConfirmDeliveryCallback | None = ... ) -> None: ... - @property def consumer_tags(self) -> list[str]: ... - def exchange_bind( self, destination: str, @@ -154,7 +97,6 @@ class Channel: arguments: Mapping[str, Any] | None = ..., callback: _OnExchangeBindCallback | None = ..., ) -> None: ... - def exchange_declare( self, exchange: str, @@ -166,14 +108,9 @@ class Channel: arguments: Mapping[str, Any] | None = ..., callback: _OnExchangeDeclareCallback | None = ..., ) -> None: ... - def exchange_delete( - self, - exchange: str | None = ..., - if_unused: bool = ..., - callback: _OnExchangeDeleteCallback | None = ..., + self, exchange: str | None = ..., if_unused: bool = ..., callback: _OnExchangeDeleteCallback | None = ... ) -> None: ... - def exchange_unbind( self, destination: str | None = ..., @@ -182,18 +119,14 @@ class Channel: arguments: Mapping[str, Any] | None = ..., callback: _OnExchangeUnbindCallback | None = ..., ) -> None: ... - def flow(self, active: bool, callback: _OnFlowCallback | None = ...) -> None: ... - @property def is_closed(self) -> bool: ... @property def is_closing(self) -> bool: ... @property def is_open(self) -> bool: ... - def open(self) -> None: ... - def queue_bind( self, queue: str, @@ -202,7 +135,6 @@ class Channel: arguments: Mapping[str, Any] | None = ..., callback: _OnQueueBindCallback | None = ..., ) -> None: ... - def queue_declare( self, queue: str, @@ -213,21 +145,10 @@ class Channel: arguments: Mapping[str, Any] | None = ..., callback: _OnQueueDeclareCallback | None = ..., ) -> None: ... - def queue_delete( - self, - queue: str, - if_unused: bool = ..., - if_empty: bool = ..., - callback: _OnQueueDeleteCallback | None = ..., - ) -> None: ... - - def queue_purge( - self, - queue: str, - callback: _OnQueuePurgeCallback | None = ..., + self, queue: str, if_unused: bool = ..., if_empty: bool = ..., callback: _OnQueueDeleteCallback | None = ... ) -> None: ... - + def queue_purge(self, queue: str, callback: _OnQueuePurgeCallback | None = ...) -> None: ... def queue_unbind( self, queue: str, @@ -236,7 +157,6 @@ class Channel: arguments: Mapping[str, Any] | None = ..., callback: _OnQueueUnbindCallback | None = ..., ) -> None: ... - def tx_commit(self, callback: _OnTxCommitCallback | None = ...) -> None: ... def tx_rollback(self, callback: _OnTxRollbackCallback | None = ...) -> None: ... def tx_select(self, callback: _OnTxSelectCallback | None = ...) -> None: ... @@ -247,7 +167,5 @@ class ContentFrameAssembler: self, frame_value: frame.Method | frame.Header | frame.Body ) -> tuple[frame.Method, frame.Header, bytes] | None: ... def _finish(self) -> tuple[frame.Method, frame.Header, bytes]: ... - def _handle_body_frame(self, body_frame) -> tuple[frame.Method, frame.Header, bytes] | None: ... - def _reset(self) -> None: ... diff --git a/pika-stubs/compat.pyi b/pika-stubs/compat.pyi index caa58bb..62f2ef6 100644 --- a/pika-stubs/compat.pyi +++ b/pika-stubs/compat.pyi @@ -27,19 +27,19 @@ str_or_bytes: tuple[Type[str], Type[bytes]] xrange: Type[range] unicode_type: Type[str] - def time_now() -> float: ... def dictkeys(dct) -> list[KeysView]: ... def dictvalues(dct) -> list[ValuesView]: ... def dict_iteritems(dct) -> ItemsView: ... def dict_itervalues(dct) -> ValuesView: ... def byte(*args: int) -> bytes: ... + class long(int): def __str__(self) -> str: ... def __repr__(self) -> str: ... + def canonical_str(value) -> str: ... def is_integer(value: Any) -> bool: ... - def as_bytes(value: AnyStr) -> bytes: ... def to_digit(value): ... def get_linux_version(release_str) -> tuple[int, int, int]: ... diff --git a/pika-stubs/connection.pyi b/pika-stubs/connection.pyi index fac8244..cfa99f6 100644 --- a/pika-stubs/connection.pyi +++ b/pika-stubs/connection.pyi @@ -16,24 +16,14 @@ from . import spec PRODUCT: str -_OnHeartbeatTimeoutCallback = Callable[['Connection', int], int] -_OnCloseCallback = Callable[['Connection', Exception], None] -_OnConnectionBlockedCallback = Callable[ - ['Connection', frame.Method[spec.Connection.Blocked]], - None, -] -_OnConnectionUnblockedCallback = Callable[ - [ - 'Connection', - frame.Method[spec.Connection.Unblocked], - ], - None, -] -_OnOpenCallback = Callable[['Connection'], None] -_OnOpenErrorCallback = Callable[['Connection', str | Exception], None] +_OnHeartbeatTimeoutCallback = Callable[["Connection", int], int] +_OnCloseCallback = Callable[["Connection", Exception], None] +_OnConnectionBlockedCallback = Callable[["Connection", frame.Method[spec.Connection.Blocked]], None] +_OnConnectionUnblockedCallback = Callable[["Connection", frame.Method[spec.Connection.Unblocked]], None] +_OnOpenCallback = Callable[["Connection"], None] +_OnOpenErrorCallback = Callable[["Connection", str | Exception], None] _OnOpenChannelCallback = Callable[[channel_.Channel], None] - class Parameters: DEFAULT_USERNAME: str = ... @@ -57,7 +47,6 @@ class Parameters: DEFAULT_SSL_PORT: int = ... DEFAULT_VIRTUAL_HOST: str = ... DEFAULT_TCP_OPTIONS: Mapping[str, Any] | None = ... - @property def blocked_connection_timeout(self) -> float | int: ... @blocked_connection_timeout.setter @@ -146,20 +135,15 @@ class ConnectionParameters(Parameters): **kwargs: Any, ): ... - class URLParameters(Parameters): - def __init__(self, url: str) -> None: ... - class SSLOptions: context: ssl.SSLContext = ... server_hostname: str | None = ... - def __init__(self, context: ssl.SSLContext, server_hostname: str | None = ...): ... - class Connection(compat.AbstractBase): ON_CONNECTION_CLOSED: str = ... @@ -185,7 +169,6 @@ class Connection(compat.AbstractBase): bytes_received: int = ... frames_sent: int = ... frames_received: int = ... - def __init__( self, parameters: Parameters | None = ..., @@ -195,13 +178,14 @@ class Connection(compat.AbstractBase): internal_connection_workflow: bool = ..., ) -> None: ... def add_on_close_callback(self, callback: _OnCloseCallback) -> None: ... - def add_on_connection_blocked_callback( self, callback: _OnConnectionBlockedCallback, ) -> None: ... - def add_on_connection_unblocked_callback( self, callback: _OnConnectionUnblockedCallback, ) -> None: ... + def add_on_connection_blocked_callback(self, callback: _OnConnectionBlockedCallback) -> None: ... + def add_on_connection_unblocked_callback(self, callback: _OnConnectionUnblockedCallback) -> None: ... def add_on_open_callback(self, callback: _OnOpenCallback) -> None: ... - def add_on_open_error_callback( self, callback: _OnOpenErrorCallback, remove_default: bool = ..., ) -> None: ... - def channel( self, channel_number: int | None = ..., on_open_callback: _OnOpenChannelCallback | None = ..., ) -> channel_.Channel: ... + def add_on_open_error_callback(self, callback: _OnOpenErrorCallback, remove_default: bool = ...) -> None: ... + def channel( + self, channel_number: int | None = ..., on_open_callback: _OnOpenChannelCallback | None = ... + ) -> channel_.Channel: ... def close(self, reply_code: int = ..., reply_text: str = ...) -> None: ... - @property def is_closed(self) -> bool: ... @property diff --git a/pika-stubs/credentials.pyi b/pika-stubs/credentials.pyi index 33e4b31..b728df3 100644 --- a/pika-stubs/credentials.pyi +++ b/pika-stubs/credentials.pyi @@ -11,30 +11,17 @@ class PlainCredentials: username: str = ... password: str = ... erase_on_connect: bool = ... - def __init__(self, username: str, password: str, erase_on_connect: bool = ...) -> None: ... - - def response_for( - self, - start: spec.Connection.Start, - ) -> tuple[str | None, str | None]: ... - + def response_for(self, start: spec.Connection.Start) -> tuple[str | None, str | None]: ... def erase_credentials(self) -> None: ... - class ExternalCredentials: TYPE: str = ... erase_on_connect: bool = ... - - def response_for( - self, - start: spec.Connection.Start, - ) -> tuple[str | None, str | None]: ... - + def response_for(self, start: spec.Connection.Start) -> tuple[str | None, str | None]: ... def erase_credentials(self) -> None: ... - _VALID_TYPES = PlainCredentials | ExternalCredentials VALID_TYPES: list[_VALID_TYPES] diff --git a/pika-stubs/exceptions.pyi b/pika-stubs/exceptions.pyi index 955ae24..dbaa3ae 100644 --- a/pika-stubs/exceptions.pyi +++ b/pika-stubs/exceptions.pyi @@ -4,175 +4,63 @@ from collections.abc import Sequence from .adapters import blocking_connection -class AMQPError(Exception): - ... - - -class AMQPConnectionError(AMQPError): - ... - - -class ConnectionOpenAborted(AMQPConnectionError): - ... - - -class StreamLostError(AMQPConnectionError): - ... - - -class IncompatibleProtocolError(AMQPConnectionError): - ... - - -class AuthenticationError(AMQPConnectionError): - ... - - -class ProbableAuthenticationError(AMQPConnectionError): - ... - - -class ProbableAccessDeniedError(AMQPConnectionError): - ... - - -class NoFreeChannels(AMQPConnectionError): - ... - - -class ConnectionWrongStateError(AMQPConnectionError): - ... - +class AMQPError(Exception): ... +class AMQPConnectionError(AMQPError): ... +class ConnectionOpenAborted(AMQPConnectionError): ... +class StreamLostError(AMQPConnectionError): ... +class IncompatibleProtocolError(AMQPConnectionError): ... +class AuthenticationError(AMQPConnectionError): ... +class ProbableAuthenticationError(AMQPConnectionError): ... +class ProbableAccessDeniedError(AMQPConnectionError): ... +class NoFreeChannels(AMQPConnectionError): ... +class ConnectionWrongStateError(AMQPConnectionError): ... class ConnectionClosed(AMQPConnectionError): - def __init__(self, reply_code: int, reply_text: str) -> None: ... - @property def reply_code(self) -> int: ... - @property def reply_text(self) -> str: ... - -class ConnectionClosedByBroker(ConnectionClosed): - ... - - -class ConnectionClosedByClient(ConnectionClosed): - ... - - -class ConnectionBlockedTimeout(AMQPConnectionError): - ... - - -class AMQPHeartbeatTimeout(AMQPConnectionError): - ... - - -class AMQPChannelError(AMQPError): - ... - - -class ChannelWrongStateError(AMQPChannelError): - ... - +class ConnectionClosedByBroker(ConnectionClosed): ... +class ConnectionClosedByClient(ConnectionClosed): ... +class ConnectionBlockedTimeout(AMQPConnectionError): ... +class AMQPHeartbeatTimeout(AMQPConnectionError): ... +class AMQPChannelError(AMQPError): ... +class ChannelWrongStateError(AMQPChannelError): ... class ChannelClosed(AMQPChannelError): - def __init__(self, reply_code: int, reply_text: str) -> None: ... - @property def reply_code(self) -> int: ... - @property def reply_text(self) -> str: ... - -class ChannelClosedByBroker(ChannelClosed): - ... - - -class ChannelClosedByClient(ChannelClosed): - ... - - -class DuplicateConsumerTag(AMQPChannelError): - ... - - -class ConsumerCancelled(AMQPChannelError): - ... - +class ChannelClosedByBroker(ChannelClosed): ... +class ChannelClosedByClient(ChannelClosed): ... +class DuplicateConsumerTag(AMQPChannelError): ... +class ConsumerCancelled(AMQPChannelError): ... class UnroutableError(AMQPChannelError): messages: Sequence[blocking_connection.ReturnedMessage] = ... - - def __init__( - self, - messages: Sequence[blocking_connection.ReturnedMessage], - ) -> None: ... - + def __init__(self, messages: Sequence[blocking_connection.ReturnedMessage]) -> None: ... class NackError(AMQPChannelError): messages: Sequence[blocking_connection.ReturnedMessage] = ... - - def __init__( - self, - messages: Sequence[blocking_connection.ReturnedMessage], - ) -> None: ... - - -class InvalidChannelNumber(AMQPError): - ... - - -class ProtocolSyntaxError(AMQPError): - ... - - -class UnexpectedFrameError(ProtocolSyntaxError): - ... - - -class ProtocolVersionMismatch(ProtocolSyntaxError): - ... - - -class BodyTooLongError(ProtocolSyntaxError): - ... - - -class InvalidFrameError(ProtocolSyntaxError): - ... - - -class InvalidFieldTypeException(ProtocolSyntaxError): - ... - - -class UnsupportedAMQPFieldException(ProtocolSyntaxError): - ... - - -class MethodNotImplemented(AMQPError): - ... - - -class ChannelError(Exception): - ... - - -class ReentrancyError(Exception): - ... - - -class ShortStringTooLong(AMQPError): - ... - - -class DuplicateGetOkCallback(ChannelError): - ... + def __init__(self, messages: Sequence[blocking_connection.ReturnedMessage]) -> None: ... + +class InvalidChannelNumber(AMQPError): ... +class ProtocolSyntaxError(AMQPError): ... +class UnexpectedFrameError(ProtocolSyntaxError): ... +class ProtocolVersionMismatch(ProtocolSyntaxError): ... +class BodyTooLongError(ProtocolSyntaxError): ... +class InvalidFrameError(ProtocolSyntaxError): ... +class InvalidFieldTypeException(ProtocolSyntaxError): ... +class UnsupportedAMQPFieldException(ProtocolSyntaxError): ... +class MethodNotImplemented(AMQPError): ... +class ChannelError(Exception): ... +class ReentrancyError(Exception): ... +class ShortStringTooLong(AMQPError): ... +class DuplicateGetOkCallback(ChannelError): ... diff --git a/pika-stubs/exchange_type.pyi b/pika-stubs/exchange_type.pyi index 9ce96dc..73cbf36 100644 --- a/pika-stubs/exchange_type.pyi +++ b/pika-stubs/exchange_type.pyi @@ -1,6 +1,5 @@ from enum import Enum - class ExchangeType(Enum): direct: str fanout: str diff --git a/pika-stubs/frame.pyi b/pika-stubs/frame.pyi index d9b0bc1..90dbdf8 100644 --- a/pika-stubs/frame.pyi +++ b/pika-stubs/frame.pyi @@ -7,8 +7,7 @@ from typing import TypeVar from . import amqp_object from . import spec -_Method = TypeVar('_Method', bound=amqp_object.Method) - +_Method = TypeVar("_Method", bound=amqp_object.Method) class Frame(amqp_object.AMQPObject): @@ -16,55 +15,40 @@ class Frame(amqp_object.AMQPObject): frame_type: int = ... channel_number: int = ... - def __init__(self, frame_type: int, channel_number: int) -> None: ... def marshal(self) -> bytes: ... - class Method(Frame, Generic[_Method]): NAME: str = ... method: _Method = ... - def __init__(self, channel_number: int, method: _Method) -> None: ... def marshal(self) -> bytes: ... - class Header(Frame): NAME: str = ... body_size: Any = ... properties: spec.BasicProperties = ... - - def __init__( - self, - channel_number: int, - body_size: int, - props: spec.BasicProperties, - ) -> None: ... + def __init__(self, channel_number: int, body_size: int, props: spec.BasicProperties) -> None: ... def marshal(self) -> bytes: ... - class Body(Frame): NAME: str = ... fragment: bytes = ... - def __init__(self, channel_number: int, fragment: bytes) -> None: ... def marshal(self) -> bytes: ... - class Heartbeat(Frame): NAME: str = ... - def __init__(self) -> None: ... def marshal(self) -> bytes: ... - class ProtocolHeader(amqp_object.AMQPObject): NAME: str = ... @@ -74,14 +58,7 @@ class ProtocolHeader(amqp_object.AMQPObject): major: int = ... minor: int = ... revision: int = ... - - def __init__( - self, - major: int | None = ..., - minor: int | None = ..., - revision: int | None = ..., - ) -> None: ... + def __init__(self, major: int | None = ..., minor: int | None = ..., revision: int | None = ...) -> None: ... def marshal(self) -> bytes: ... - def decode_frame(data_in: bytes) -> tuple[int, Frame | None]: ... diff --git a/pika-stubs/spec.pyi b/pika-stubs/spec.pyi index fcde45e..85d730b 100644 --- a/pika-stubs/spec.pyi +++ b/pika-stubs/spec.pyi @@ -43,23 +43,20 @@ SYNTAX_ERROR: Literal[502] TRANSIENT_DELIVERY_MODE: Literal[1] UNEXPECTED_FRAME: Literal[505] - class Connection(amqp_object.Class): INDEX: Literal[0x000A] - NAME: Literal['Connection'] - + NAME: Literal["Connection"] class Start(amqp_object.Method): INDEX: Literal[0x000A000A] - NAME: Literal['Connection.Start'] + NAME: Literal["Connection.Start"] version_major: int = ... version_minor: int = ... server_properties: Mapping[str, Any] | None = ... mechanisms: str = ... locales: str = ... - def __init__( self, version_major: int = ..., @@ -68,23 +65,19 @@ class Connection(amqp_object.Class): mechanisms: str = ..., locales: str = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.Start: ... def encode(self) -> list[bytes]: ... - class StartOk(amqp_object.Method): INDEX: Literal[0x000A000B] - NAME: Literal['Connection.StartOk'] + NAME: Literal["Connection.StartOk"] client_properties: Mapping[str, Any] | None = ... mechanism: str = ... response: str | None = ... locale: str = ... - def __init__( self, client_properties: Mapping[str, Any] | None = ..., @@ -92,291 +85,207 @@ class Connection(amqp_object.Class): response: str | None = ..., locale: str = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.StartOk: ... def encode(self) -> list[bytes]: ... - class Secure(amqp_object.Method): INDEX: Literal[0x000A0014] - NAME: Literal['Connection.Secure'] + NAME: Literal["Connection.Secure"] challenge: str | None = ... - def __init__(self, challenge: str | None = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.Secure: ... def encode(self) -> list[bytes]: ... - class SecureOk(amqp_object.Method): INDEX: Literal[0x000A0015] - NAME: Literal['Connection.SecureOk'] + NAME: Literal["Connection.SecureOk"] response: str | None = ... - def __init__(self, response: str | None = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.SecureOk: ... def encode(self) -> list[bytes]: ... - class Tune(amqp_object.Method): INDEX: Literal[0x000A001E] - NAME: Literal['Connection.Tune'] + NAME: Literal["Connection.Tune"] channel_max: int = ... frame_max: int = ... heartbeat: int = ... - def __init__(self, channel_max: int = ..., frame_max: int = ..., heartbeat: int = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.Tune: ... def encode(self) -> list[bytes]: ... - class TuneOk(amqp_object.Method): INDEX: Literal[0x000A001F] - NAME: Literal['Connection.TuneOk'] + NAME: Literal["Connection.TuneOk"] channel_max: int = ... frame_max: int = ... heartbeat: int = ... - - def __init__( - self, - channel_max: int = ..., - frame_max: int = ..., - heartbeat: int = ..., - ) -> None: ... - + def __init__(self, channel_max: int = ..., frame_max: int = ..., heartbeat: int = ...) -> None: ... @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.TuneOk: ... def encode(self) -> list[bytes]: ... - class Open(amqp_object.Method): INDEX: Literal[0x000A0028] - NAME: Literal['Connection.Open'] + NAME: Literal["Connection.Open"] virtual_host: str = ... capabilities: str = ... insist: bool = ... - - def __init__( - self, - virtual_host: str = ..., - capabilities: str = ..., - insist: bool = ..., - ) -> None: ... - + def __init__(self, virtual_host: str = ..., capabilities: str = ..., insist: bool = ...) -> None: ... @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.Open: ... def encode(self) -> list[bytes]: ... - class OpenOk(amqp_object.Method): INDEX: Literal[0x000A0029] - NAME: Literal['Connection.OpenOk'] + NAME: Literal["Connection.OpenOk"] known_hosts: str = ... - def __init__(self, known_hosts: str = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.OpenOk: ... def encode(self) -> list[bytes]: ... - class Close(amqp_object.Method): INDEX: Literal[0x000A0032] - NAME: Literal['Connection.Close'] + NAME: Literal["Connection.Close"] reply_code: int | None = ... reply_text: str = ... class_id: int | None = ... method_id: int | None = ... - def __init__( - self, - reply_code: int | None = ..., - reply_text: str = ..., - class_id: int | None = ..., - method_id: int | None = ..., + self, reply_code: int | None = ..., reply_text: str = ..., class_id: int | None = ..., method_id: int | None = ... ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.Close: ... def encode(self) -> list[bytes]: ... - class CloseOk(amqp_object.Method): INDEX: Literal[0x000A0033] - NAME: Literal['Connection.CloseOk'] - + NAME: Literal["Connection.CloseOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.CloseOk: ... def encode(self) -> list[bytes]: ... - class Blocked(amqp_object.Method): INDEX: Literal[0x000A003C] - NAME: Literal['Connection.Blocked'] + NAME: Literal["Connection.Blocked"] reason: str = ... - def __init__(self, reason: str = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.Blocked: ... def encode(self) -> list[bytes]: ... - class Unblocked(amqp_object.Method): INDEX: Literal[0x000A003D] - NAME: Literal['Connection.Unblocked'] - + NAME: Literal["Connection.Unblocked"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Connection.Unblocked: ... def encode(self) -> list[bytes]: ... - class Channel(amqp_object.Class): INDEX: Literal[0x0014] - NAME: Literal['Channel'] - + NAME: Literal["Channel"] class Open(amqp_object.Method): INDEX: Literal[0x0014000A] - NAME: Literal['Channel.Open'] + NAME: Literal["Channel.Open"] out_of_band: str = ... - def __init__(self, out_of_band: str = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Channel.Open: ... def encode(self) -> list[bytes]: ... - class OpenOk(amqp_object.Method): INDEX: Literal[0x0014000B] - NAME: Literal['Channel.OpenOk'] + NAME: Literal["Channel.OpenOk"] channel_id: str = ... - def __init__(self, channel_id: str = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Channel.OpenOk: ... def encode(self) -> list[bytes]: ... - class Flow(amqp_object.Method): INDEX: Literal[0x00140014] - NAME: Literal['Channel.Flow'] + NAME: Literal["Channel.Flow"] active: bool | None = ... - def __init__(self, active: bool | None = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Channel.Flow: ... def encode(self) -> list[bytes]: ... - class FlowOk(amqp_object.Method): INDEX: Literal[0x00140015] - NAME: Literal['Channel.FlowOk'] + NAME: Literal["Channel.FlowOk"] active: bool | None = ... - def __init__(self, active: bool | None = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Channel.FlowOk: ... def encode(self) -> list[bytes]: ... - class Close(amqp_object.Method): INDEX: Literal[0x00140028] - NAME: Literal['Channel.Close'] + NAME: Literal["Channel.Close"] reply_code: int | None = ... reply_text: str = ... class_id: int | None = ... method_id: int | None = ... - def __init__( - self, - reply_code: int | None = ..., - reply_text: str = ..., - class_id: int | None = ..., - method_id: int | None = ..., + self, reply_code: int | None = ..., reply_text: str = ..., class_id: int | None = ..., method_id: int | None = ... ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Channel.Close: ... def encode(self) -> list[bytes]: ... - class CloseOk(amqp_object.Method): INDEX: Literal[0x00140029] - NAME: Literal['Channel.CloseOk'] - + NAME: Literal["Channel.CloseOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Channel.CloseOk: ... def encode(self) -> list[bytes]: ... - class Access(amqp_object.Class): INDEX: Literal[0x001E] - NAME: Literal['Access'] - + NAME: Literal["Access"] class Request(amqp_object.Method): INDEX: Literal[0x001E000A] - NAME: Literal['Access.Request'] + NAME: Literal["Access.Request"] realm: str = ... exclusive: bool = ... @@ -384,7 +293,6 @@ class Access(amqp_object.Class): active: bool = ... write: bool = ... read: bool = ... - def __init__( self, realm: str = ..., @@ -394,38 +302,30 @@ class Access(amqp_object.Class): write: bool = ..., read: bool = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Access.Request: ... def encode(self) -> list[bytes]: ... - class RequestOk(amqp_object.Method): INDEX: Literal[0x001E000B] - NAME: Literal['Access.RequestOk'] + NAME: Literal["Access.RequestOk"] ticket: int = ... - def __init__(self, ticket: int = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Access.RequestOk: ... def encode(self) -> list[bytes]: ... - class Exchange(amqp_object.Class): INDEX: Literal[0x0028] - NAME: Literal['Exchange'] - + NAME: Literal["Exchange"] class Declare(amqp_object.Method): INDEX: Literal[0x0028000A] - NAME: Literal['Exchange.Declare'] + NAME: Literal["Exchange.Declare"] ticket: int = ... exchange: str | None = ... @@ -436,7 +336,6 @@ class Exchange(amqp_object.Class): internal: bool = ... nowait: bool = ... arguments: Mapping[str, Any] | None = ... - def __init__( self, ticket: int = ..., @@ -449,63 +348,44 @@ class Exchange(amqp_object.Class): nowait: bool = ..., arguments: Mapping[str, Any] | None = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Exchange.Declare: ... def encode(self) -> list[bytes]: ... - class DeclareOk(amqp_object.Method): INDEX: Literal[0x0028000B] - NAME: Literal['Exchange.DeclareOk'] - + NAME: Literal["Exchange.DeclareOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Exchange.DeclareOk: ... def encode(self) -> list[bytes]: ... - class Delete(amqp_object.Method): INDEX: Literal[0x00280014] - NAME: Literal['Exchange.Delete'] + NAME: Literal["Exchange.Delete"] ticket: int = ... exchange: str | None = ... if_unused: bool = ... nowait: bool = ... - - def __init__( - self, - ticket: int = ..., - exchange: str | None = ..., - if_unused: bool = ..., - nowait: bool = ..., - ) -> None: ... - + def __init__(self, ticket: int = ..., exchange: str | None = ..., if_unused: bool = ..., nowait: bool = ...) -> None: ... @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Exchange.Delete: ... def encode(self) -> list[bytes]: ... - class DeleteOk(amqp_object.Method): INDEX: Literal[0x00280015] - NAME: Literal['Exchange.DeleteOk'] - + NAME: Literal["Exchange.DeleteOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Exchange.DeleteOk: ... def encode(self) -> list[bytes]: ... - class Bind(amqp_object.Method): INDEX: Literal[0x0028001E] - NAME: Literal['Exchange.Bind'] + NAME: Literal["Exchange.Bind"] ticket: int = ... destination: str | None = ... @@ -513,7 +393,6 @@ class Exchange(amqp_object.Class): routing_key: str = ... nowait: bool = ... arguments: Mapping[str, Any] | None = ... - def __init__( self, ticket: int = ..., @@ -523,28 +402,22 @@ class Exchange(amqp_object.Class): nowait: bool = ..., arguments: Mapping[str, Any] | None = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Exchange.Bind: ... def encode(self) -> list[bytes]: ... - class BindOk(amqp_object.Method): INDEX: Literal[0x0028001F] - NAME: Literal['Exchange.BindOk'] - + NAME: Literal["Exchange.BindOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Exchange.BindOk: ... def encode(self) -> list[bytes]: ... - class Unbind(amqp_object.Method): INDEX: Literal[0x00280028] - NAME: Literal['Exchange.Unbind'] + NAME: Literal["Exchange.Unbind"] ticket: int = ... destination: str | None = ... @@ -552,7 +425,6 @@ class Exchange(amqp_object.Class): routing_key: str = ... nowait: bool = ... arguments: Mapping[str, Any] | None = ... - def __init__( self, ticket: int = ..., @@ -562,34 +434,27 @@ class Exchange(amqp_object.Class): nowait: bool = ..., arguments: Mapping[str, Any] | None = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Exchange.Unbind: ... def encode(self) -> list[bytes]: ... - class UnbindOk(amqp_object.Method): INDEX: Literal[0x00280033] - NAME: Literal['Exchange.UnbindOk'] - + NAME: Literal["Exchange.UnbindOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Exchange.UnbindOk: ... def encode(self) -> list[bytes]: ... - class Queue(amqp_object.Class): INDEX: Literal[0x0032] - NAME: Literal['Queue'] - + NAME: Literal["Queue"] class Declare(amqp_object.Method): INDEX: Literal[0x0032000A] - NAME: Literal['Queue.Declare'] + NAME: Literal["Queue.Declare"] ticket: int = ... queue: str = ... @@ -599,7 +464,6 @@ class Queue(amqp_object.Class): auto_delete: bool = ... nowait: bool = ... arguments: Mapping[str, Any] | None = ... - def __init__( self, ticket: int = ..., @@ -611,39 +475,29 @@ class Queue(amqp_object.Class): nowait: bool = ..., arguments: Mapping[str, Any] | None = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Queue.Declare: ... def encode(self) -> list[bytes]: ... - class DeclareOk(amqp_object.Method): INDEX: Literal[0x0032000B] - NAME: Literal['Queue.DeclareOk'] + NAME: Literal["Queue.DeclareOk"] queue: str | None = ... message_count: int | None = ... consumer_count: int | None = ... - def __init__( - self, - queue: str | None = ..., - message_count: int | None = ..., - consumer_count: int | None = ..., + self, queue: str | None = ..., message_count: int | None = ..., consumer_count: int | None = ... ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Queue.DeclareOk: ... def encode(self) -> list[bytes]: ... - class Bind(amqp_object.Method): INDEX: Literal[0x00320014] - NAME: Literal['Queue.Bind'] + NAME: Literal["Queue.Bind"] ticket: int = ... queue: str = ... @@ -651,7 +505,6 @@ class Queue(amqp_object.Class): routing_key: str = ... nowait: bool = ... arguments: Mapping[str, Any] | None = ... - def __init__( self, ticket: int = ..., @@ -661,113 +514,80 @@ class Queue(amqp_object.Class): nowait: bool = ..., arguments: Mapping[str, Any] | None = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Queue.Bind: ... def encode(self) -> list[bytes]: ... - class BindOk(amqp_object.Method): INDEX: Literal[0x00320015] - NAME: Literal['Queue.BindOk'] - + NAME: Literal["Queue.BindOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Queue.BindOk: ... def encode(self) -> list[bytes]: ... - class Purge(amqp_object.Method): INDEX: Literal[0x0032001E] - NAME: Literal['Queue.Purge'] + NAME: Literal["Queue.Purge"] ticket: int = ... queue: str = ... nowait: bool = ... - - def __init__( - self, - ticket: int = ..., - queue: str = ..., - nowait: bool = ..., - ) -> None: ... - + def __init__(self, ticket: int = ..., queue: str = ..., nowait: bool = ...) -> None: ... @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Queue.Purge: ... def encode(self) -> list[bytes]: ... - class PurgeOk(amqp_object.Method): INDEX: Literal[0x0032001F] - NAME: Literal['Queue.PurgeOk'] + NAME: Literal["Queue.PurgeOk"] message_count: int | None = ... - def __init__(self, message_count: int | None = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Queue.PurgeOk: ... def encode(self) -> list[bytes]: ... - class Delete(amqp_object.Method): INDEX: Literal[0x00320028] - NAME: Literal['Queue.Delete'] + NAME: Literal["Queue.Delete"] ticket: int = ... queue: str = ... if_unused: bool = ... if_empty: bool = ... nowait: bool = ... - def __init__( - self, - ticket: int = ..., - queue: str = ..., - if_unused: bool = ..., - if_empty: bool = ..., - nowait: bool = ..., + self, ticket: int = ..., queue: str = ..., if_unused: bool = ..., if_empty: bool = ..., nowait: bool = ... ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Queue.Delete: ... def encode(self) -> list[bytes]: ... - class DeleteOk(amqp_object.Method): INDEX: Literal[0x00320029] - NAME: Literal['Queue.DeleteOk'] + NAME: Literal["Queue.DeleteOk"] message_count: int | None = ... - def __init__(self, message_count: int | None = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Queue.DeleteOk: ... def encode(self) -> list[bytes]: ... - class Unbind(amqp_object.Method): INDEX: Literal[0x00320032] - NAME: Literal['Queue.Unbind'] + NAME: Literal["Queue.Unbind"] ticket: int = ... queue: str = ... exchange: str | None = ... routing_key: str = ... arguments: Mapping[str, Any] | None = ... - def __init__( self, ticket: int = ..., @@ -776,67 +596,48 @@ class Queue(amqp_object.Class): routing_key: str = ..., arguments: Mapping[str, Any] | None = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Queue.Unbind: ... def encode(self) -> list[bytes]: ... - class UnbindOk(amqp_object.Method): INDEX: Literal[0x00320033] - NAME: Literal['Queue.UnbindOk'] - + NAME: Literal["Queue.UnbindOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Queue.UnbindOk: ... def encode(self) -> list[bytes]: ... - class Basic(amqp_object.Class): INDEX: Literal[0x003C] - NAME: Literal['Basic'] - + NAME: Literal["Basic"] class Qos(amqp_object.Method): INDEX: Literal[0x003C000A] - NAME: Literal['Basic.Qos'] + NAME: Literal["Basic.Qos"] prefetch_size: int = ... prefetch_count: int = ... global_qos: bool = ... - - def __init__( - self, - prefetch_size: int = ..., - prefetch_count: int = ..., - global_qos: bool = ..., - ) -> None: ... - + def __init__(self, prefetch_size: int = ..., prefetch_count: int = ..., global_qos: bool = ...) -> None: ... @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.Qos: ... def encode(self) -> list[bytes]: ... - class QosOk(amqp_object.Method): INDEX: Literal[0x003C000B] - NAME: Literal['Basic.QosOk'] - + NAME: Literal["Basic.QosOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.QosOk: ... def encode(self) -> list[bytes]: ... - class Consume(amqp_object.Method): INDEX: Literal[0x003C0014] - NAME: Literal['Basic.Consume'] + NAME: Literal["Basic.Consume"] ticket: int = ... queue: str = ... @@ -846,7 +647,6 @@ class Basic(amqp_object.Class): exclusive: bool = ... nowait: bool = ... arguments: Mapping[str, Any] | None = ... - def __init__( self, ticket: int = ..., @@ -858,120 +658,87 @@ class Basic(amqp_object.Class): nowait: bool = ..., arguments: Mapping[str, Any] | None = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.Consume: ... def encode(self) -> list[bytes]: ... - class ConsumeOk(amqp_object.Method): INDEX: Literal[0x003C0015] - NAME: Literal['Basic.ConsumeOk'] + NAME: Literal["Basic.ConsumeOk"] consumer_tag: int | None = ... - def __init__(self, consumer_tag: int | None = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.ConsumeOk: ... def encode(self) -> list[bytes]: ... - class Cancel(amqp_object.Method): INDEX: Literal[0x003C001E] - NAME: Literal['Basic.Cancel'] + NAME: Literal["Basic.Cancel"] consumer_tag: int | None = ... nowait: bool = ... - def __init__(self, consumer_tag: int | None = ..., nowait: bool = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.Cancel: ... def encode(self) -> list[bytes]: ... - class CancelOk(amqp_object.Method): INDEX: Literal[0x003C001F] - NAME: Literal['Basic.CancelOk'] + NAME: Literal["Basic.CancelOk"] consumer_tag: int | None = ... - def __init__(self, consumer_tag: int | None = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.CancelOk: ... def encode(self) -> list[bytes]: ... - class Publish(amqp_object.Method): INDEX: Literal[0x003C0028] - NAME: Literal['Basic.Publish'] + NAME: Literal["Basic.Publish"] ticket: int = ... exchange: str = ... routing_key: str = ... mandatory: bool = ... immediate: bool = ... - def __init__( - self, - ticket: int = ..., - exchange: str = ..., - routing_key: str = ..., - mandatory: bool = ..., - immediate: bool = ..., + self, ticket: int = ..., exchange: str = ..., routing_key: str = ..., mandatory: bool = ..., immediate: bool = ... ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.Publish: ... def encode(self) -> list[bytes]: ... - class Return(amqp_object.Method): INDEX: Literal[0x003C0032] - NAME: Literal['Basic.Return'] + NAME: Literal["Basic.Return"] reply_code: int | None = ... reply_text: str = ... exchange: str | None = ... routing_key: str | None = ... - def __init__( - self, - reply_code: int | None = ..., - reply_text: str = ..., - exchange: str | None = ..., - routing_key: str | None = ..., + self, reply_code: int | None = ..., reply_text: str = ..., exchange: str | None = ..., routing_key: str | None = ... ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.Return: ... def encode(self) -> list[bytes]: ... - class Deliver(amqp_object.Method): INDEX: Literal[0x003C003C] - NAME: Literal['Basic.Deliver'] + NAME: Literal["Basic.Deliver"] consumer_tag: str | None = ... delivery_tag: int | None = ... redelivered: bool = ... exchange: str | None = ... routing_key: str | None = ... - def __init__( self, consumer_tag: str | None = ..., @@ -980,46 +747,33 @@ class Basic(amqp_object.Class): exchange: str | None = ..., routing_key: str | None = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.Deliver: ... def encode(self) -> list[bytes]: ... - class Get(amqp_object.Method): INDEX: Literal[0x003C0046] - NAME: Literal['Basic.Get'] + NAME: Literal["Basic.Get"] ticket: int = ... queue: str = ... no_ack: bool = ... - - def __init__( - self, - ticket: int = ..., - queue: str = ..., - no_ack: bool = ..., - ) -> None: ... - + def __init__(self, ticket: int = ..., queue: str = ..., no_ack: bool = ...) -> None: ... @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.Get: ... def encode(self) -> list[bytes]: ... - class GetOk(amqp_object.Method): INDEX: Literal[0x003C0047] - NAME: Literal['Basic.GetOk'] + NAME: Literal["Basic.GetOk"] delivery_tag: int | None = ... redelivered: bool = ... exchange: str | None = ... routing_key: str | None = ... message_count: int | None = ... - def __init__( self, delivery_tag: int | None = ..., @@ -1028,234 +782,172 @@ class Basic(amqp_object.Class): routing_key: str | None = ..., message_count: int | None = ..., ) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.GetOk: ... def encode(self) -> list[bytes]: ... - class GetEmpty(amqp_object.Method): INDEX: Literal[0x003C0048] - NAME: Literal['Basic.GetEmpty'] + NAME: Literal["Basic.GetEmpty"] cluster_id: str = ... - def __init__(self, cluster_id: str = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.GetEmpty: ... def encode(self) -> list[bytes]: ... - class Ack(amqp_object.Method): INDEX: Literal[0x003C0050] - NAME: Literal['Basic.Ack'] + NAME: Literal["Basic.Ack"] delivery_tag: int = ... multiple: bool = ... - def __init__(self, delivery_tag: int = ..., multiple: bool = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.Ack: ... def encode(self) -> list[bytes]: ... - class Reject(amqp_object.Method): INDEX: Literal[0x003C005A] - NAME: Literal['Basic.Reject'] + NAME: Literal["Basic.Reject"] delivery_tag: int | None = ... requeue: bool = ... - def __init__(self, delivery_tag: int | None = ..., requeue: bool = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.Reject: ... def encode(self) -> list[bytes]: ... - class RecoverAsync(amqp_object.Method): INDEX: Literal[0x003C0064] - NAME: Literal['Basic.RecoverAsync'] + NAME: Literal["Basic.RecoverAsync"] requeue: bool = ... - def __init__(self, requeue: bool = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.RecoverAsync: ... def encode(self) -> list[bytes]: ... - class Recover(amqp_object.Method): INDEX: Literal[0x003C006E] - NAME: Literal['Basic.Recover'] + NAME: Literal["Basic.Recover"] requeue: bool = ... - def __init__(self, requeue: bool = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.Recover: ... def encode(self) -> list[bytes]: ... - class RecoverOk(amqp_object.Method): INDEX: Literal[0x003C006F] - NAME: Literal['Basic.RecoverOk'] - + NAME: Literal["Basic.RecoverOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.RecoverOk: ... def encode(self) -> list[bytes]: ... - class Nack(amqp_object.Method): INDEX: Literal[0x003C0078] - NAME: Literal['Basic.Nack'] + NAME: Literal["Basic.Nack"] delivery_tag: int = ... multiple: bool = ... requeue: bool = ... - - def __init__( - self, - delivery_tag: int = ..., - multiple: bool = ..., - requeue: bool = ..., - ) -> None: ... - + def __init__(self, delivery_tag: int = ..., multiple: bool = ..., requeue: bool = ...) -> None: ... @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Basic.Nack: ... def encode(self) -> list[bytes]: ... - class Tx(amqp_object.Class): INDEX: Literal[0x005A] - NAME: Literal['Tx'] - + NAME: Literal["Tx"] class Select(amqp_object.Method): INDEX: Literal[0x005A000A] - NAME: Literal['Tx.Select'] - + NAME: Literal["Tx.Select"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Tx.Select: ... def encode(self) -> list[bytes]: ... - class SelectOk(amqp_object.Method): INDEX: Literal[0x005A000B] - NAME: Literal['Tx.SelectOk'] - + NAME: Literal["Tx.SelectOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Tx.SelectOk: ... def encode(self) -> list[bytes]: ... - class Commit(amqp_object.Method): INDEX: Literal[0x005A0014] - NAME: Literal['Tx.Commit'] - + NAME: Literal["Tx.Commit"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Tx.Commit: ... def encode(self) -> list[bytes]: ... - class CommitOk(amqp_object.Method): INDEX: Literal[0x005A0015] - NAME: Literal['Tx.CommitOk'] - + NAME: Literal["Tx.CommitOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Tx.CommitOk: ... def encode(self) -> list[bytes]: ... - class Rollback(amqp_object.Method): INDEX: Literal[0x005A001E] - NAME: Literal['Tx.Rollback'] - + NAME: Literal["Tx.Rollback"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Tx.Rollback: ... def encode(self) -> list[bytes]: ... - class RollbackOk(amqp_object.Method): INDEX: Literal[0x005A001F] - NAME: Literal['Tx.RollbackOk'] - + NAME: Literal["Tx.RollbackOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Tx.RollbackOk: ... def encode(self) -> list[bytes]: ... - class Confirm(amqp_object.Class): INDEX: Literal[0x0055] - NAME: Literal['Confirm'] - + NAME: Literal["Confirm"] class Select(amqp_object.Method): INDEX: Literal[0x0055000A] - NAME: Literal['Confirm.Select'] + NAME: Literal["Confirm.Select"] nowait: bool = ... - def __init__(self, nowait: bool = ...) -> None: ... - @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Confirm.Select: ... def encode(self) -> list[bytes]: ... - class SelectOk(amqp_object.Method): INDEX: Literal[0x0055000B] - NAME: Literal['Confirm.SelectOk'] - + NAME: Literal["Confirm.SelectOk"] @property def synchronous(self) -> bool: ... - def decode(self, encoded: bytes, offset: int = ...) -> Confirm.SelectOk: ... def encode(self) -> list[bytes]: ... - class BasicProperties(amqp_object.Properties): CLASS: Type[Basic] = ... INDEX: Literal[0x003C] - NAME: Literal['BasicProperties'] + NAME: Literal["BasicProperties"] FLAG_CONTENT_TYPE: int = ... FLAG_CONTENT_ENCODING: int = ... @@ -1286,7 +978,6 @@ class BasicProperties(amqp_object.Properties): user_id: str | None = ... app_id: str | None = ... cluster_id: str | None = ... - def __init__( self, content_type: str | None = ..., @@ -1304,13 +995,10 @@ class BasicProperties(amqp_object.Properties): app_id: str | None = ..., cluster_id: str | None = ..., ) -> None: ... - def decode(self, encoded: bytes, offset: int = ...) -> BasicProperties: ... def encode(self) -> list[bytes]: ... - methods: Mapping[int, amqp_object.Method] props: Mapping[int, amqp_object.Properties] - def has_content(methodNumber: int) -> bool: ... From e82d95207971d9710de87c63549ff3569add8ca7 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Mon, 17 Jan 2022 15:33:54 -0600 Subject: [PATCH 09/11] allow forward reference without quote --- pika-stubs/adapters/asyncio_connection.pyi | 6 +++--- pika-stubs/adapters/base_connection.pyi | 6 +++--- pika-stubs/adapters/select_connection.pyi | 2 +- pika-stubs/adapters/tornado_connection.pyi | 6 +++--- pika-stubs/channel.pyi | 10 +++++----- pika-stubs/connection.pyi | 12 ++++++------ 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pika-stubs/adapters/asyncio_connection.pyi b/pika-stubs/adapters/asyncio_connection.pyi index 0bf2587..8f23d8c 100644 --- a/pika-stubs/adapters/asyncio_connection.pyi +++ b/pika-stubs/adapters/asyncio_connection.pyi @@ -8,9 +8,9 @@ from .. import connection from . import base_connection from .utils import connection_workflow -_OnCloseCallback = Callable[["AsyncioConnection", Exception], None] -_OnOpenCallback = Callable[["AsyncioConnection"], None] -_OnOpenErrorCallback = Callable[["AsyncioConnection", str | Exception], None] +_OnCloseCallback = Callable[[AsyncioConnection, Exception], None] +_OnOpenCallback = Callable[[AsyncioConnection], None] +_OnOpenErrorCallback = Callable[[AsyncioConnection, str | Exception], None] class AsyncioConnection(base_connection.BaseConnection[asyncio.AbstractEventLoop]): def __init__( diff --git a/pika-stubs/adapters/base_connection.pyi b/pika-stubs/adapters/base_connection.pyi index 586218e..94dc5e2 100644 --- a/pika-stubs/adapters/base_connection.pyi +++ b/pika-stubs/adapters/base_connection.pyi @@ -10,9 +10,9 @@ from .. import connection from .utils import connection_workflow from .utils import nbio_interface -_OnCloseCallback = Callable[["BaseConnection", Exception], None] -_OnOpenCallback = Callable[["BaseConnection"], None] -_OnOpenErrorCallback = Callable[["BaseConnection", str | Exception], None] +_OnCloseCallback = Callable[[BaseConnection, Exception], None] +_OnOpenCallback = Callable[[BaseConnection], None] +_OnOpenErrorCallback = Callable[[BaseConnection, str | Exception], None] _IOLoop = TypeVar("_IOLoop") diff --git a/pika-stubs/adapters/select_connection.pyi b/pika-stubs/adapters/select_connection.pyi index f7cb33d..0678536 100644 --- a/pika-stubs/adapters/select_connection.pyi +++ b/pika-stubs/adapters/select_connection.pyi @@ -20,7 +20,7 @@ _OnCloseCallback = Callable[[base_connection.BaseConnection, Exception], None] _OnOpenCallback = Callable[[base_connection.BaseConnection], None] _OnOpenErrorCallback = Callable[[base_connection.BaseConnection, str | Exception], None] -class SelectConnection(base_connection.BaseConnection["IOLoop"]): +class SelectConnection(base_connection.BaseConnection[IOLoop]): def __init__( self, parameters: connection.Parameters | None = ..., diff --git a/pika-stubs/adapters/tornado_connection.pyi b/pika-stubs/adapters/tornado_connection.pyi index 73be212..3fd782e 100644 --- a/pika-stubs/adapters/tornado_connection.pyi +++ b/pika-stubs/adapters/tornado_connection.pyi @@ -10,9 +10,9 @@ from . import base_connection from .utils import connection_workflow from .utils import nbio_interface -_OnCloseCallback = Callable[["TornadoConnection", Exception], None] -_OnOpenCallback = Callable[["TornadoConnection"], None] -_OnOpenErrorCallback = Callable[["TornadoConnection", str | Exception], None] +_OnCloseCallback = Callable[[TornadoConnection, Exception], None] +_OnOpenCallback = Callable[[TornadoConnection], None] +_OnOpenErrorCallback = Callable[[TornadoConnection, str | Exception], None] class TornadoConnection(base_connection.BaseConnection[tornado.ioloop.IOLoop]): def __init__( diff --git a/pika-stubs/channel.pyi b/pika-stubs/channel.pyi index 68c1628..f9cbfc0 100644 --- a/pika-stubs/channel.pyi +++ b/pika-stubs/channel.pyi @@ -18,24 +18,24 @@ MAX_CHANNELS: Literal[65535] # per AMQP 0.9.1 spec. _OnAckNackCallback = Callable[[frame.Method[spec.Basic.Ack | spec.Basic.Nack]], None] _OnConfirmDeliveryCallback = Callable[[frame.Method[spec.Confirm.SelectOk]], None] _OnBasicConsumeCallback = Callable[[frame.Method[spec.Basic.ConsumeOk]], None] -_OnBasicGetCallback = Callable[["Channel", spec.Basic.GetOk, spec.BasicProperties, bytes], None] +_OnBasicGetCallback = Callable[[Channel, spec.Basic.GetOk, spec.BasicProperties, bytes], None] _OnBasicRecoverCallback = Callable[[frame.Method[spec.Basic.RecoverOk]], None] _OnBasicQosCallback = Callable[[frame.Method[spec.Basic.QosOk]], None] _OnBasicCancelCallback = Callable[[frame.Method[spec.Basic.CancelOk]], None] -_OnCloseCallback = Callable[["Channel", Exception], None] +_OnCloseCallback = Callable[[Channel, Exception], None] _OnExchangeBindCallback = Callable[[frame.Method[spec.Exchange.BindOk]], None] _OnExchangeDeclareCallback = Callable[[frame.Method[spec.Exchange.DeclareOk]], None] _OnExchangeDeleteCallback = Callable[[frame.Method[spec.Exchange.DeleteOk]], None] _OnExchangeUnbindCallback = Callable[[frame.Method[spec.Exchange.UnbindOk]], None] _OnFlowCallback = Callable[[bool], None] -_OnMessageCallback = Callable[["Channel", spec.Basic.Deliver, spec.BasicProperties, bytes], None] -_OnOpenCallback = Callable[["Channel"], None] +_OnMessageCallback = Callable[[Channel, spec.Basic.Deliver, spec.BasicProperties, bytes], None] +_OnOpenCallback = Callable[[Channel], None] _OnQueueBindCallback = Callable[[frame.Method[spec.Queue.BindOk]], None] _OnQueueDeclareCallback = Callable[[frame.Method[spec.Queue.DeclareOk]], None] _OnQueueDeleteCallback = Callable[[frame.Method[spec.Queue.DeleteOk]], None] _OnQueuePurgeCallback = Callable[[frame.Method[spec.Queue.PurgeOk]], None] _OnQueueUnbindCallback = Callable[[frame.Method[spec.Queue.UnbindOk]], None] -_OnReturnCallback = Callable[["Channel", spec.Basic.Return, spec.BasicProperties, bytes], None] +_OnReturnCallback = Callable[[Channel, spec.Basic.Return, spec.BasicProperties, bytes], None] _OnTxCommitCallback = Callable[[spec.Tx.CommitOk], None] _OnTxRollbackCallback = Callable[[spec.Tx.RollbackOk], None] _OnTxSelectCallback = Callable[[spec.Tx.SelectOk], None] diff --git a/pika-stubs/connection.pyi b/pika-stubs/connection.pyi index cfa99f6..82f2d09 100644 --- a/pika-stubs/connection.pyi +++ b/pika-stubs/connection.pyi @@ -16,12 +16,12 @@ from . import spec PRODUCT: str -_OnHeartbeatTimeoutCallback = Callable[["Connection", int], int] -_OnCloseCallback = Callable[["Connection", Exception], None] -_OnConnectionBlockedCallback = Callable[["Connection", frame.Method[spec.Connection.Blocked]], None] -_OnConnectionUnblockedCallback = Callable[["Connection", frame.Method[spec.Connection.Unblocked]], None] -_OnOpenCallback = Callable[["Connection"], None] -_OnOpenErrorCallback = Callable[["Connection", str | Exception], None] +_OnHeartbeatTimeoutCallback = Callable[[Connection, int], int] +_OnCloseCallback = Callable[[Connection, Exception], None] +_OnConnectionBlockedCallback = Callable[[Connection, frame.Method[spec.Connection.Blocked]], None] +_OnConnectionUnblockedCallback = Callable[[Connection, frame.Method[spec.Connection.Unblocked]], None] +_OnOpenCallback = Callable[[Connection], None] +_OnOpenErrorCallback = Callable[[Connection, str | Exception], None] _OnOpenChannelCallback = Callable[[channel_.Channel], None] class Parameters: From 4dfab7b0959dd53fc12b7ead8115a6db6092b4c8 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Mon, 17 Jan 2022 15:54:30 -0600 Subject: [PATCH 10/11] fix strict mypy warnings --- .../adapters/utils/io_services_utils.pyi | 2 +- pika-stubs/channel.pyi | 14 +++++++++---- pika-stubs/compat.pyi | 21 ++++++++++++------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/pika-stubs/adapters/utils/io_services_utils.pyi b/pika-stubs/adapters/utils/io_services_utils.pyi index dee3081..ade6232 100644 --- a/pika-stubs/adapters/utils/io_services_utils.pyi +++ b/pika-stubs/adapters/utils/io_services_utils.pyi @@ -7,7 +7,7 @@ from typing import Callable from . import nbio_interface -def check_callback_arg(callback: Callable, name: str) -> None: ... +def check_callback_arg(callback: Callable[..., Any], name: str) -> None: ... def check_fd_arg(fd: int) -> None: ... class SocketConnectionMixin: diff --git a/pika-stubs/channel.pyi b/pika-stubs/channel.pyi index f9cbfc0..2216d42 100644 --- a/pika-stubs/channel.pyi +++ b/pika-stubs/channel.pyi @@ -5,8 +5,10 @@ from collections.abc import Sequence from typing import Any from typing import AnyStr from typing import Callable +from typing import TypeVar from typing_extensions import Literal +from . import amqp_object from . import callback from . import connection as connection_ from . import frame @@ -161,11 +163,15 @@ class Channel: def tx_rollback(self, callback: _OnTxRollbackCallback | None = ...) -> None: ... def tx_select(self, callback: _OnTxSelectCallback | None = ...) -> None: ... +_Method = TypeVar("_Method", bound=amqp_object.Method) + class ContentFrameAssembler: def __init__(self) -> None: ... def process( - self, frame_value: frame.Method | frame.Header | frame.Body - ) -> tuple[frame.Method, frame.Header, bytes] | None: ... - def _finish(self) -> tuple[frame.Method, frame.Header, bytes]: ... - def _handle_body_frame(self, body_frame) -> tuple[frame.Method, frame.Header, bytes] | None: ... + self, frame_value: frame.Method[_Method] | frame.Header | frame.Body + ) -> tuple[frame.Method[_Method], frame.Header, bytes] | None: ... + def _finish(self) -> tuple[frame.Method[_Method], frame.Header, bytes]: ... + def _handle_body_frame( + self, body_frame: frame.Method[_Method] | frame.Header | frame.Body + ) -> tuple[frame.Method[_Method], frame.Header, bytes] | None: ... def _reset(self) -> None: ... diff --git a/pika-stubs/compat.pyi b/pika-stubs/compat.pyi index 62f2ef6..0e60a68 100644 --- a/pika-stubs/compat.pyi +++ b/pika-stubs/compat.pyi @@ -7,11 +7,12 @@ from typing import AnyStr from typing import ItemsView from typing import KeysView from typing import Type +from typing import TypeVar from typing import ValuesView PY2: bool PY3: bool -RE_NUM: re.Pattern +RE_NUM: re.Pattern[str] ON_LINUX: bool ON_OSX: bool @@ -28,21 +29,25 @@ xrange: Type[range] unicode_type: Type[str] def time_now() -> float: ... -def dictkeys(dct) -> list[KeysView]: ... -def dictvalues(dct) -> list[ValuesView]: ... -def dict_iteritems(dct) -> ItemsView: ... -def dict_itervalues(dct) -> ValuesView: ... + +_T1 = TypeVar("_T1") +_T2 = TypeVar("_T2") + +def dictkeys(dct: dict[_T1, _T2]) -> list[KeysView[_T1]]: ... +def dictvalues(dct: dict[_T1, _T2]) -> list[ValuesView[_T2]]: ... +def dict_iteritems(dct: dict[_T1, _T2]) -> ItemsView[_T1, _T2]: ... +def dict_itervalues(dct: dict[_T1, _T2]) -> ValuesView[_T2]: ... def byte(*args: int) -> bytes: ... class long(int): def __str__(self) -> str: ... def __repr__(self) -> str: ... -def canonical_str(value) -> str: ... +def canonical_str(value: Any) -> str: ... def is_integer(value: Any) -> bool: ... def as_bytes(value: AnyStr) -> bytes: ... -def to_digit(value): ... -def get_linux_version(release_str) -> tuple[int, int, int]: ... +def to_digit(value: str) -> int: ... +def get_linux_version(release_str: str) -> tuple[int, int, int]: ... HAVE_SIGNAL: bool EINTR_IS_EXPOSED: bool From dddec719a8df4fe4510feefb12e9c65b1d508252 Mon Sep 17 00:00:00 2001 From: Bao Trinh Date: Mon, 17 Jan 2022 16:02:13 -0600 Subject: [PATCH 11/11] CI: install self as package to enable stubtest --- .github/workflows/check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index b2b8aa8..370ac6d 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -26,7 +26,7 @@ jobs: run: python -m pip install -U pip - name: Install dependencies - run: pip install -r requirements-dev.txt + run: pip install -r requirements-dev.txt .[dev] - name: Lint with flake8 run: flake8