Skip to content

Commit

Permalink
fix: fix TypeError with the new _outgoing_call decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikaalund committed Jan 19, 2022
1 parent a645647 commit dfb1389
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

Nothing so far.

## [0.12.1] - 2022-01-19

### Fixed

- Fix `TypeError` with the new `_outgoing_call` decorator.

## [0.12.0] - 2022-01-19

### Added
Expand Down
29 changes: 15 additions & 14 deletions asyncio_mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ def __init__(
]


# TODO: Simplify the logic that surrounds `self._outgoing_calls_sem` with
# `nullcontext` when we support Python 3.10 (`nullcontext` becomes async-aware in
# 3.10). See: https://docs.python.org/3/library/contextlib.html#contextlib.nullcontext
def _outgoing_call(method: Callable[..., Awaitable[T]]) -> Callable[..., Awaitable[T]]:
@functools.wraps(method)
async def decorated(self, *args: Any, **kwargs: Any) -> T:
if not self._outgoing_calls_sem:
return await method(self, *args, **kwargs)

async with self._outgoing_calls_sem:
return await method(self, *args, **kwargs)

return decorated


class Client:
def __init__(
self,
Expand Down Expand Up @@ -230,20 +245,6 @@ async def force_disconnect(self) -> None:
if not self._disconnected.done():
self._disconnected.set_result(None)

# TODO: Simplify the logic that surrounds `self._outgoing_calls_sem` with
# `nullcontext` when we support Python 3.10 (`nullcontext` becomes async-aware in
# 3.10). See: https://docs.python.org/3/library/contextlib.html#contextlib.nullcontext
def _outgoing_call(self, func: Callable[..., Awaitable[T]]) -> Callable[..., Awaitable[T]]:
@functools.wraps(func)
async def decorated(*args: Any, **kwargs: Any) -> T:
if not self._outgoing_calls_sem:
return await func(*args, **kwargs)

async with self._outgoing_calls_sem:
return await func(*args, **kwargs)

return decorated

@_outgoing_call
async def subscribe(self, *args: Any, timeout: int = 10, **kwargs: Any) -> int:
result, mid = self._client.subscribe(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion asyncio_mqtt/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# SPDX-License-Identifier: BSD-3-Clause
__version__ = "0.12.0"
__version__ = "0.12.1"

0 comments on commit dfb1389

Please sign in to comment.