Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #1987

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:

# autoformat and lint Python code
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
rev: v0.4.3
hooks:
- id: ruff
types_or:
Expand All @@ -43,7 +43,7 @@ repos:
exclude: zmq/constants.py

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.10.0
hooks:
- id: mypy
files: zmq/.*
Expand All @@ -55,7 +55,7 @@ repos:
additional_dependencies:
- types-paramiko
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: check-executables-have-shebangs
Expand Down
6 changes: 3 additions & 3 deletions buildutils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def ifndefs():
lines = ['#define _PYZMQ_UNDEFINED (-9999)']
for name in all_names:
if not no_prefix(name):
name = 'ZMQ_%s' % name
name = f'ZMQ_{name}'
lines.append(ifndef_t.format(name))
return dict(ZMQ_IFNDEFS='\n'.join(lines))

Expand Down Expand Up @@ -104,11 +104,11 @@ def promoted_constants():

def generate_file(fname, ns_func, dest_dir="."):
"""generate a constants file from its template"""
with open(pjoin(root, 'buildutils', 'templates', '%s' % fname)) as f:
with open(pjoin(root, 'buildutils', 'templates', f'{fname}')) as f:
tpl = f.read()
out = tpl.format(**ns_func())
dest = pjoin(dest_dir, fname)
print("generating %s from template" % dest)
print(f"generating {dest} from template")
with open(dest, 'w') as f:
f.write(out)
if fname.endswith(".py"):
Expand Down
4 changes: 2 additions & 2 deletions examples/asyncio/helloworld_pubsub_dealerrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def msg_sub(self, msg: str) -> None:
class HelloWorldMessage:
def __init__(self, url: str = '127.0.0.1', port: int = 5555):
# get ZeroMQ version
print("Current libzmq version is %s" % zmq.zmq_version())
print("Current pyzmq version is %s" % zmq.__version__)
print(f"Current libzmq version is {zmq.zmq_version()}")
print(f"Current pyzmq version is {zmq.__version__}")

self.url = f"tcp://{url}:{port}"
# pub/sub and dealer/router
Expand Down
4 changes: 2 additions & 2 deletions examples/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def produce(url, ident):
ctx = zmq.Context.instance()
s = ctx.socket(zmq.PUSH)
s.connect(url)
print("Producing %s" % ident)
print(f"Producing {ident}")
for i in range(MSGS):
s.send(('%s: %i' % (ident, time.time())).encode('utf8'))
time.sleep(1)
print("Producer %s done" % ident)
print(f"Producer {ident} done")
s.close()


Expand Down
2 changes: 1 addition & 1 deletion examples/draft/client-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
print(f'server recvd {msg.bytes!r} from {msg.routing_id!r}')
server.send_string('reply %i' % i, routing_id=msg.routing_id)
reply = client.recv_string()
print('client recvd %r' % reply)
print(f'client recvd {reply!r}')
time.sleep(0.1)
client.close()

Expand Down
4 changes: 2 additions & 2 deletions examples/eventloop/asyncweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def slow_responder() -> None:
i = 0
while True:
frame, msg = socket.recv_multipart()
print("\nworker received %r\n" % msg, end='')
print(f"\nworker received {msg!r}\n", end='')
time.sleep(random.randint(1, 5))
socket.send_multipart([frame, msg + b" to you too, #%i" % i])
i += 1
Expand All @@ -52,7 +52,7 @@ async def get(self) -> None:

# finish web request with worker's reply
reply = await s.recv_string()
print("\nfinishing with %r\n" % reply)
print(f"\nfinishing with {reply!r}\n")
self.write(reply)


Expand Down
2 changes: 1 addition & 1 deletion examples/heartbeat/heartbeater.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def handle_pong(self, msg):
if msg[1] == str(self.lifetime):
self.responses.add(msg[0])
else:
print("got bad heartbeat (possibly old?): %s" % msg[1])
print(f"got bad heartbeat (possibly old?): {msg[1]}")


# sub.setsockopt(zmq.SUBSCRIBE)
Expand Down
8 changes: 4 additions & 4 deletions examples/mongodb/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ def add_document(self, doc: Dict) -> Optional[str]:
try:
self._table.insert(doc)
except Exception as e:
return 'Error: %s' % e
return f'Error: {e}'
return None

def get_document_by_keys(self, keys: Dict[str, Any]) -> Union[Dict, str, None]:
"""
Attempts to return a single document from database table that matches
each key/value in keys dictionary.
"""
print('attempting to retrieve document using keys: %s' % keys)
print(f'attempting to retrieve document using keys: {keys}')
try:
return self._table.find_one(keys)
except Exception as e:
return 'Error: %s' % e
return f'Error: {e}'

def start(self) -> None:
context = zmq.Context()
Expand All @@ -69,7 +69,7 @@ def start(self) -> None:
msg = socket.recv_multipart()
print("Received msg: ", msg)
if len(msg) != 3:
error_msg = 'invalid message received: %s' % msg
error_msg = f'invalid message received: {msg}'
print(error_msg)
reply = [msg[0], error_msg]
socket.send_multipart(reply)
Expand Down
2 changes: 1 addition & 1 deletion examples/monitoring/simple_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def line() -> None:
print('-' * 40)


print("libzmq-%s" % zmq.zmq_version())
print(f"libzmq-{zmq.zmq_version()}")
if zmq.zmq_version_info() < (4, 0):
raise RuntimeError("monitoring in libzmq version < 4.0 is not supported")

Expand Down
4 changes: 2 additions & 2 deletions examples/monitoring/zmq_monitor_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def event_monitor_thread_async(
monitor: a zmq monitor socket, from calling: my_zmq_socket.get_monitor_socket()
loop: an asyncio event loop, from calling zmq.asyncio.asyncio.get_event_loop() , whens starting a thread it does not contains an event loop
"""
print("libzmq-%s" % zmq.zmq_version())
print(f"libzmq-{zmq.zmq_version()}")
if zmq.zmq_version_info() < (4, 0):
raise RuntimeError("monitoring in libzmq version < 4.0 is not supported")

Expand Down Expand Up @@ -99,7 +99,7 @@ def event_monitor_thread(monitor: zmq.Socket) -> None:
monitor: a zmq monitor socket, from calling: my_zmq_socket.get_monitor_socket()
"""

print("libzmq-%s" % zmq.zmq_version())
print(f"libzmq-{zmq.zmq_version()}")
if zmq.zmq_version_info() < (4, 0):
raise RuntimeError("monitoring in libzmq version < 4.0 is not supported")

Expand Down
2 changes: 1 addition & 1 deletion examples/pubsub/topics_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main() -> None:
print("Receiving messages on ALL topics...")
s.setsockopt(zmq.SUBSCRIBE, b'')
else:
print("Receiving messages on topics: %s ..." % topics)
print(f"Receiving messages on topics: {topics} ...")
for t in topics:
s.setsockopt(zmq.SUBSCRIBE, t.encode('utf-8'))
print
Expand Down
2 changes: 1 addition & 1 deletion perf/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def main():

test = args.test
full_name = full_names[test]
print("Running %s test" % full_name)
print(f"Running {full_name} test")
fname = test + '.pickle'
import pandas as pd

Expand Down
8 changes: 4 additions & 4 deletions perf/perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ def throughput(url, count, size, poll=False, copy=True, quiet=False):
if not quiet:
print("message size : %8i [B]" % size)
print("message count : %8i [msgs]" % count)
print("send only : %8.0f [msg/s]" % send_throughput)
print("mean throughput: %8.0f [msg/s]" % throughput)
print("mean throughput: %12.3f [Mb/s]" % megabits)
print("test time : %12.3f [s]" % elapsed)
print(f"send only : {send_throughput:8.0f} [msg/s]")
print(f"mean throughput: {throughput:8.0f} [msg/s]")
print(f"mean throughput: {megabits:12.3f} [Mb/s]")
print(f"test time : {elapsed:12.3f} [s]")
ctx.destroy()
return (send_throughput, throughput)

Expand Down
4 changes: 2 additions & 2 deletions zmq/_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def _handle_recv(self):
elif kind == 'recv':
recv = self._shadow_sock.recv
else:
raise ValueError("Unhandled recv event type: %r" % kind)
raise ValueError(f"Unhandled recv event type: {kind!r}")

kwargs['flags'] |= _zmq.DONTWAIT
try:
Expand Down Expand Up @@ -662,7 +662,7 @@ def _handle_send(self):
elif kind == 'send':
send = self._shadow_sock.send
else:
raise ValueError("Unhandled send event type: %r" % kind)
raise ValueError(f"Unhandled send event type: {kind!r}")

kwargs['flags'] |= _zmq.DONTWAIT
try:
Expand Down
2 changes: 1 addition & 1 deletion zmq/auth/certs.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def load_certificate(
break

if public_key is None:
raise ValueError("No public key found in %s" % filename)
raise ValueError(f"No public key found in {filename}")

return public_key, secret_key

Expand Down
2 changes: 1 addition & 1 deletion zmq/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if 'PYZMQ_BACKEND' in os.environ:
backend = os.environ['PYZMQ_BACKEND']
if backend in ('cython', 'cffi'):
backend = 'zmq.backend.%s' % backend
backend = f'zmq.backend.{backend}'
_ns = select_backend(backend)
else:
# default to cython, fallback to cffi
Expand Down
4 changes: 2 additions & 2 deletions zmq/backend/cffi/_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def zmq_poll(sockets, timeout):
# don't allow negative ms_passed,
# which can happen on old Python versions without time.monotonic.
warnings.warn(
"Negative elapsed time for interrupted poll: %s."
" Did the clock change?" % ms_passed,
f"Negative elapsed time for interrupted poll: {ms_passed}."
" Did the clock change?",
RuntimeWarning,
)
ms_passed = 0
Expand Down
2 changes: 1 addition & 1 deletion zmq/backend/cffi/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def set(self, option, value):

if isinstance(value, bytes):
if opt_type != _OptType.bytes:
raise TypeError("not a bytes sockopt: %s" % option)
raise TypeError(f"not a bytes sockopt: {option}")
length = len(value)

c_value_pointer, c_sizet = initialize_opt_pointer(option, value, length)
Expand Down
16 changes: 8 additions & 8 deletions zmq/backend/cython/_zmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,13 +755,13 @@ def set(self, option: C.int, optval):

if opt_type == _OptType.bytes:
if not isinstance(optval, bytes):
raise TypeError('expected bytes, got: %r' % optval)
raise TypeError(f'expected bytes, got: {optval!r}')
optval_c = PyBytes_AsString(optval)
sz = PyBytes_Size(optval)
_setsockopt(self.handle, option, optval_c, sz)
elif opt_type == _OptType.int64:
if not isinstance(optval, int):
raise TypeError('expected int, got: %r' % optval)
raise TypeError(f'expected int, got: {optval!r}')
optval_int64_c = optval
_setsockopt(self.handle, option, address(optval_int64_c), sizeof(int64_t))
else:
Expand All @@ -771,7 +771,7 @@ def set(self, option: C.int, optval):
# sockopts will still raise just the same, but it will be libzmq doing
# the raising.
if not isinstance(optval, int):
raise TypeError('expected int, got: %r' % optval)
raise TypeError(f'expected int, got: {optval!r}')
optval_int_c = optval
_setsockopt(self.handle, option, address(optval_int_c), sizeof(int))

Expand Down Expand Up @@ -876,7 +876,7 @@ def bind(self, addr):
addr = addr_b.decode('utf-8')

if not isinstance(addr_b, bytes):
raise TypeError('expected str, got: %r' % addr)
raise TypeError(f'expected str, got: {addr!r}')
c_addr = addr_b
rc = zmq_bind(self.handle, c_addr)
if rc != 0:
Expand Down Expand Up @@ -921,7 +921,7 @@ def connect(self, addr):
if isinstance(addr, str):
addr = addr.encode('utf-8')
if not isinstance(addr, bytes):
raise TypeError('expected str, got: %r' % addr)
raise TypeError(f'expected str, got: {addr!r}')
c_addr = addr

while True:
Expand Down Expand Up @@ -957,7 +957,7 @@ def unbind(self, addr):
if isinstance(addr, str):
addr = addr.encode('utf-8')
if not isinstance(addr, bytes):
raise TypeError('expected str, got: %r' % addr)
raise TypeError(f'expected str, got: {addr!r}')
c_addr = addr

rc = zmq_unbind(self.handle, c_addr)
Expand Down Expand Up @@ -987,7 +987,7 @@ def disconnect(self, addr):
if isinstance(addr, str):
addr = addr.encode('utf-8')
if not isinstance(addr, bytes):
raise TypeError('expected str, got: %r' % addr)
raise TypeError(f'expected str, got: {addr!r}')
c_addr = addr

rc = zmq_disconnect(self.handle, c_addr)
Expand Down Expand Up @@ -1523,7 +1523,7 @@ def zmq_poll(sockets, timeout: C.int = -1):
free(pollitems)
raise TypeError(
"Socket must be a 0MQ socket, an integer fd or have "
"a fileno() method: %r" % s
f"a fileno() method: {s!r}"
)

ms_passed: int = 0
Expand Down
2 changes: 1 addition & 1 deletion zmq/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def __init__(self, min_version: str, msg: str = "Feature"):
self.version = _zmq_version

def __repr__(self):
return "ZMQVersionError('%s')" % str(self)
return f"ZMQVersionError('{str(self)}')"

def __str__(self):
return f"{self.msg} requires libzmq >= {self.min_version}, have {self.version}"
Expand Down
5 changes: 2 additions & 3 deletions zmq/eventloop/zmqstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,9 @@ def close(self, linger: int | None = None) -> None:
# hopefully this happened promptly after close,
# otherwise somebody else may have the FD
warnings.warn(
"Unregistering FD %s after closing socket. "
f"Unregistering FD {self._fd} after closing socket. "
"This could result in unregistering handlers for the wrong socket. "
"Please use stream.close() instead of closing the socket directly."
% self._fd,
"Please use stream.close() instead of closing the socket directly.",
stacklevel=2,
)
self.io_loop.remove_handler(self._fd)
Expand Down
2 changes: 1 addition & 1 deletion zmq/green/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _get_descriptors(self):
else:
raise TypeError(
'Socket must be a 0MQ socket, an integer fd '
'or have a fileno() method: %r' % socket
f'or have a fileno() method: {socket!r}'
)

if flags & zmq.POLLIN:
Expand Down
Loading
Loading