Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 29, 2024
1 parent e40a028 commit 7c4545b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
1 change: 0 additions & 1 deletion tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import zmq
import zmq.asyncio as zaio


pytestmark = pytest.mark.anyio


Expand Down
32 changes: 19 additions & 13 deletions zmq/_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
cast,
)

import zmq as _zmq
from anyio import create_task_group, sleep
from anyioutils import Future, create_task

import zmq as _zmq
from zmq import EVENTS, POLLIN, POLLOUT


Expand Down Expand Up @@ -89,9 +90,7 @@ def wake_raw(*args):
if not watcher.done():
watcher.set_result(None)

watcher.add_done_callback(
lambda f: self._unwatch_raw_sockets(*raw_sockets)
)
watcher.add_done_callback(lambda f: self._unwatch_raw_sockets(*raw_sockets))

wrapped_sockets: list[_AsyncSocket] = []

Expand Down Expand Up @@ -266,7 +265,9 @@ async def recv( # type: ignore
Recommend using recv_multipart instead.
"""
async with create_task_group() as tg:
return await self._add_recv_event(tg, 'recv', dict(flags=flags, copy=copy, track=track))
return await self._add_recv_event(
tg, 'recv', dict(flags=flags, copy=copy, track=track)
)

async def send_multipart( # type: ignore
self, msg_parts: Any, flags: int = 0, copy: bool = True, track=False, **kwargs
Expand All @@ -280,7 +281,9 @@ async def send_multipart( # type: ignore
kwargs['track'] = track
async with create_task_group() as tg:
self._init_io_state(tg)
return await self._add_send_event(tg, 'send_multipart', msg=msg_parts, kwargs=kwargs)
return await self._add_send_event(
tg, 'send_multipart', msg=msg_parts, kwargs=kwargs
)

async def send( # type: ignore
self,
Expand All @@ -307,9 +310,9 @@ async def send( # type: ignore
def _deserialize(self, recvd, load):
"""Deserialize with Futures"""
return load(recvd)
#f = self._Future()
# f = self._Future()

#def _chain(_):
# def _chain(_):
# """Chain result through serialization to recvd"""
# if f.done():
# # chained future may be cancelled, which means nobody is going to get this result
Expand All @@ -334,18 +337,18 @@ def _deserialize(self, recvd, load):
# else:
# f.set_result(loaded)

#recvd.add_done_callback(_chain)
# recvd.add_done_callback(_chain)

#def _chain_cancel(_):
# def _chain_cancel(_):
# """Chain cancellation from f to recvd"""
# if recvd.done():
# return
# if f.cancelled():
# recvd.cancel()

#f.add_done_callback(_chain_cancel)
# f.add_done_callback(_chain_cancel)

#return await f.wait()
# return await f.wait()

async def poll(self, timeout=None, flags=_zmq.POLLIN) -> int: # type: ignore
"""poll the socket for events
Expand Down Expand Up @@ -418,6 +421,7 @@ def _call_later(self, task_group, delay, callback):
Tornado and asyncio happen to both have ioloop.call_later
with the same signature.
"""

async def call_later():
await sleep(delay)
callback()
Expand Down Expand Up @@ -484,7 +488,9 @@ async def _add_recv_event(self, task_group, kind, kwargs=None, future=None):
self._add_io_state(task_group, POLLIN)
return await f.wait()

async def _add_send_event(self, task_group, kind, msg=None, kwargs=None, future=None):
async def _add_send_event(
self, task_group, kind, msg=None, kwargs=None, future=None
):
"""Add a send event, returning the corresponding Future"""
f = future or self._Future()
# attempt send with DONTWAIT if no futures are waiting
Expand Down
3 changes: 2 additions & 1 deletion zmq/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import selectors
import sys
import warnings
from anyioutils import Future
from asyncio import SelectorEventLoop
from weakref import WeakKeyDictionary

from anyioutils import Future

import zmq as _zmq
from zmq import _future

Expand Down
4 changes: 3 additions & 1 deletion zmq/sugar/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,9 @@ def send_json(self, obj: Any, flags: int = 0, **kwargs) -> None:
msg = jsonapi.dumps(obj, **kwargs)
return self.send(msg, flags=flags, **send_kwargs)

async def recv_json(self, flags: int = 0, **kwargs) -> list | str | int | float | dict:
async def recv_json(
self, flags: int = 0, **kwargs
) -> list | str | int | float | dict:
"""Receive a Python object as a message using json to serialize.
Keyword arguments are passed on to json.loads
Expand Down

0 comments on commit 7c4545b

Please sign in to comment.