Skip to content

Commit

Permalink
Fix ruff UP findings
Browse files Browse the repository at this point in the history
  • Loading branch information
timwoj committed Dec 7, 2024
1 parent f6c5221 commit 9c64242
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 21 deletions.
4 changes: 2 additions & 2 deletions bindings/python/broker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __ne__(self, other):
utc = UTC()

Version = _broker.Version
Version.string = lambda: "%u.%u.%u" % (Version.MAJOR, Version.MINOR, Version.PATCH)
Version.string = lambda: f"{Version.MAJOR}.{Version.MINOR}.{Version.PATCH}"

now = _broker.now

Expand Down Expand Up @@ -573,7 +573,7 @@ def __init__(self, x=None):
_broker.Data.__init__(self, v)

elif isinstance(x, set) or isinstance(x, frozenset):
s = _broker.Set(([Data(i) for i in x]))
s = _broker.Set([Data(i) for i in x])
_broker.Data.__init__(self, s)

elif isinstance(x, dict) or isinstance(x, types.MappingProxyType):
Expand Down
12 changes: 3 additions & 9 deletions broker-throughput/broker-throughput.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,17 @@ def printStats(stats):
global last_t, last_sent_ev1
now = time.time()
# rate = "sending at {:.2f} ev/s, receiving at {:.2f} ev/s".format(total_sent_ev1 / (now - first_t) , total_recv_ev1 / (now - first_t))
rate = "sending at {:.2f} ev/s, receiving at {:.2f} ev/s".format(
(total_sent_ev1 - last_sent_ev1) / (now - last_t), ev1 / dt.total_seconds()
)
rate = f"sending at {(total_sent_ev1 - last_sent_ev1) / (now - last_t):.2f} ev/s, receiving at {ev1 / dt.total_seconds():.2f} ev/s"
last_t = now
last_sent_ev1 = total_sent_ev1

print(
"{} dt={} ev{}={} (total {} of {}) {}".format(
t, dt, event, ev1, total_recv_ev1, total_sent_ev1, rate
)
f"{t} dt={dt} ev{event}={ev1} (total {total_recv_ev1} of {total_sent_ev1}) {rate}"
)


def sendBatch(p, num):
event_1s = [
broker.zeek.Event("event_{}".format(event), [i, "test"]) for i in range(num)
]
event_1s = [broker.zeek.Event(f"event_{event}", [i, "test"]) for i in range(num)]
for e in event_1s:
p.publish(e)

Expand Down
2 changes: 1 addition & 1 deletion doc/_examples/ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
# Wait for "pong" reply event.
(t, d) = sub.get()
pong = broker.zeek.Event(d)
print("received {}{}".format(pong.name(), pong.args()))
print(f"received {pong.name()}{pong.args()}")
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# built documents.
#
# The short X.Y version.
with open("../VERSION", "r") as f:
with open("../VERSION") as f:
version = f.readline().strip()

# The full version, including alpha/beta/rc tags.
Expand Down
2 changes: 1 addition & 1 deletion doc/extensions/numsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, env):
sphinx.domains.std.StandardDomain.__init__(self, env)

def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
res = super(CustomStandardDomain, self).resolve_xref(
res = super().resolve_xref(
env, fromdocname, builder, typ, target, node, contnode
)

Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ exclude = ["auxil",
"tests/btest//store"]

[lint]
select = ["C4", "I", "ISC"]
select = ["C4", "I", "ISC", "UP"]
4 changes: 2 additions & 2 deletions tests/btest/scripts/extract-json-keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def rec_scan_keys(xs, prefix):
if not prefix:
full_key = key
else:
full_key = "{}.{}".format(prefix, key)
full_key = f"{prefix}.{key}"
keys.append(full_key)
if type(val) is dict:
rec_scan_keys(val, full_key)
Expand All @@ -47,7 +47,7 @@ def do_scan(fname):
else:
required_keys.split(",")
# Check that each required key exists in the input.
print("required_keys: {}".format(required_keys))
print(f"required_keys: {required_keys}")
for key in required_keys:
if not key in keys:
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion tests/btest/scripts/wire_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def write_op_msg(fd, src, dst, tag, topic, buf):
fd.send(src.bytes) # sender UUID
fd.send(dst.bytes) # receiver UUID
fd.send(int(tag).to_bytes(1, byteorder="big", signed=False)) # msg type
fd.send(int(1).to_bytes(2, byteorder="big", signed=False)) # ttl
fd.send((1).to_bytes(2, byteorder="big", signed=False)) # ttl
fd.send(len(topic).to_bytes(2, byteorder="big", signed=False))
fd.send(topic.encode())
fd.send(buf)
Expand Down
2 changes: 1 addition & 1 deletion tests/python/broker-cluster-benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def prepare_environment(self):
file_path = os.path.join(self.test_dir, "integration", file_name)
with zipfile.ZipFile(file_path, "r") as zip_ref:
zip_ref.extractall(self.input_dir)
with open(os.path.join(self.recording_dir, "expected-tpl.conf"), mode="r") as f:
with open(os.path.join(self.recording_dir, "expected-tpl.conf")) as f:
format_vars = {"path": self.recording_dir}
self.expected = f.read() % format_vars

Expand Down
2 changes: 0 additions & 2 deletions tests/python/zeek.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import multiprocessing
import unittest
from datetime import datetime
Expand Down

0 comments on commit 9c64242

Please sign in to comment.