Skip to content

Commit ba2af11

Browse files
committed
more f-string lint
1 parent d3a8ab4 commit ba2af11

21 files changed

Lines changed: 51 additions & 69 deletions

File tree

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
from datetime import date
9696

9797
project = 'ipyparallel'
98-
copyright = '%04d, The IPython Development Team' % date.today().year
98+
copyright = f'{date.today().year}, The IPython Development Team'
9999
author = 'The IPython Development Team'
100100

101101
# The version info for the project you're documenting, acts as replacement for

docs/source/examples/customresults.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def sleep_here(count, t):
3030
import sys
3131
import time
3232

33-
print("hi from engine %i" % id)
33+
print(f"hi from engine {id}")
3434
sys.stdout.flush()
3535
time.sleep(t)
3636
return count, t
@@ -52,12 +52,12 @@ def sleep_here(count, t):
5252
for msg_id in finished:
5353
# we know these are done, so don't worry about blocking
5454
ar = rc.get_result(msg_id)
55-
print("job id %s finished on engine %i" % (msg_id, ar.engine_id))
55+
print(f"job id {msg_id} finished on engine {ar.engine_id}")
5656
print("with stdout:")
5757
print(' ' + ar.stdout.replace('\n', '\n ').rstrip())
5858
print("and results:")
5959

6060
# note that each job in a map always returns a list of length chunksize
6161
# even if chunksize == 1
6262
for count, t in ar.get():
63-
print(" item %i: slept for %.2fs" % (count, t))
63+
print(f" item {count}: slept for {t:.2f}s")

docs/source/examples/daVinci Word Count/pwordfreq.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,18 @@ def pwordfreq(view, fnames):
6868
block = nlines // n
6969
for i in range(n):
7070
chunk = lines[i * block : i * (block + 1)]
71-
with open('davinci%i.txt' % i, 'w', encoding='utf8') as f:
71+
with open(f'davinci{i}.txt', 'w', encoding='utf8') as f:
7272
f.write('\n'.join(chunk))
7373

7474
try: # python2
7575
cwd = os.path.abspath(os.getcwdu())
7676
except AttributeError: # python3
7777
cwd = os.path.abspath(os.getcwd())
78-
fnames = [os.path.join(cwd, 'davinci%i.txt' % i) for i in range(n)]
78+
fnames = [os.path.join(cwd, f'davinci{i}.txt') for i in range(n)]
7979
tic = time.time()
8080
pfreqs = pwordfreq(view, fnames)
8181
toc = time.time()
8282
print_wordfreq(freqs)
83-
print("Took %.3f s to calculate on %i engines" % (toc - tic, len(view.targets)))
83+
print(f"Took {toc - tic:.3f}s to calculate on {len(view.targets)} engines")
8484
# cleanup split files
8585
map(os.remove, fnames)

docs/source/examples/dagdeps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def main(nodes, edges):
100100

101101
client = parallel.Client()
102102
view = client.load_balanced_view()
103-
print("submitting %i tasks with %i dependencies" % (nodes, edges))
103+
print(f"submitting {nodes} tasks with {edges} dependencies")
104104
results = submit_jobs(view, G, jobs)
105105
print("waiting for results")
106106
client.wait_interactive()

docs/source/examples/interengine/communicator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def __init__(self, interface='tcp://*', identity=None):
2121
# bind to ports
2222
port = self.socket.bind_to_random_port(interface)
2323
pub_port = self.pub.bind_to_random_port(interface)
24-
self.url = interface + ":%i" % port
25-
self.pub_url = interface + ":%i" % pub_port
24+
self.url = f"{interface}:{port}"
25+
self.pub_url = f"{interface}:{pub_port}"
2626
# guess first public IP from socket
2727
self.location = socket.gethostbyname_ex(socket.gethostname())[-1][0]
2828
self.peers = {}

docs/source/examples/itermapresult.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
# create a Reference to `id`. This will be a different value on each engine
3535
ref = ipp.Reference('id')
3636
print("sleeping for `id` seconds on each engine")
37-
tic = time.time()
37+
tic = time.perf_counter()
3838
ar = dv.apply(time.sleep, ref)
3939
for i, r in enumerate(ar):
40-
print("%i: %.3f" % (i, time.time() - tic))
40+
print(f"{i}: {time.perf_counter() - tic:.3f}")
4141

4242

4343
def sleep_here(t):
@@ -50,22 +50,22 @@ def sleep_here(t):
5050
# one call per task
5151
print("running with one call per task")
5252
amr = v.map(sleep_here, [0.01 * t for t in range(100)])
53-
tic = time.time()
53+
tic = time.perf_counter()
5454
for i, r in enumerate(amr):
55-
print("task %i on engine %i: %.3f" % (i, r[0], time.time() - tic))
55+
print(f"task {i} on engine {r[0]}: {time.perf_counter() - tic:.3f}")
5656

5757
print("running with four calls per task")
5858
# with chunksize, we can have four calls per task
5959
amr = v.map(sleep_here, [0.01 * t for t in range(100)], chunksize=4)
60-
tic = time.time()
60+
tic = time.perf_counter()
6161
for i, r in enumerate(amr):
62-
print("task %i on engine %i: %.3f" % (i, r[0], time.time() - tic))
62+
print(f"task {i} on engine {r[0]}: {time.perf_counter() - tic:.3f}")
6363

6464
print("running with two calls per task, with unordered results")
6565
# We can even iterate through faster results first, with ordered=False
6666
amr = v.map(
6767
sleep_here, [0.01 * t for t in range(100, 0, -1)], ordered=False, chunksize=2
6868
)
69-
tic = time.time()
69+
tic = time.perf_counter()
7070
for i, r in enumerate(amr):
71-
print("slept %.2fs on engine %i: %.3f" % (r[1], r[0], time.time() - tic))
71+
print(f"slept {r[1]:.2f}s on engine {r[0]}: {time.perf_counter() - tic:.3f}")

docs/source/examples/pi/parallelpi.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import ipyparallel as ipp
3030

3131
# Files with digits of pi (10m digits each)
32-
filestring = 'pi200m.ascii.%(i)02dof20'
33-
files = [filestring % {'i': i} for i in range(1, 21)]
32+
filestring = 'pi200m.ascii.{}of20'
33+
files = [filestring.format(i) for i in range(1, 21)]
3434

3535
# Connect to the IPython cluster
3636
c = ipp.Client()
@@ -42,7 +42,7 @@
4242
v = c[:]
4343
v.block = True
4444
# fetch the pi-files
45-
print("downloading %i files of pi" % n)
45+
print(f"downloading {n} files of pi")
4646
v.map(fetch_pi_file, files[:n]) # noqa: F821
4747
print("done")
4848

@@ -60,10 +60,10 @@
6060
freqs150m = reduce_freqs(freqs_all)
6161
t2 = clock()
6262
digits_per_second8 = n * 10.0e6 / (t2 - t1)
63-
print("Digits per second (%i engines, %i0m digits): " % (n, n), digits_per_second8)
63+
print(f"Digits per second ({n} engines, {n}0m digits): ", digits_per_second8)
6464

6565
print("Speedup: ", digits_per_second8 / digits_per_second1)
6666

6767
plot_two_digit_freqs(freqs150m)
68-
plt.title("2 digit sequences in %i0m digits of pi" % n)
68+
plt.title(f"2 digit sequences in {n}0m digits of pi")
6969
plt.show()

docs/source/examples/task_profiler.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ def main():
6060
]
6161
stime = sum(times)
6262

63-
print(
64-
"executing %i tasks, totalling %.1f secs on %i engines"
65-
% (opts.n, stime, nengines)
66-
)
63+
print(f"executing {opts.n} tasks, totalling {stime:.1f} secs on {nengines} engines")
6764
time.sleep(1)
6865
start = time.perf_counter()
6966
amr = view.map(time.sleep, times)
@@ -74,8 +71,8 @@ def main():
7471
scale = stime / ptime
7572

7673
print(f"executed {stime:.1f} secs in {ptime:.1f} secs")
77-
print("%.3fx parallel performance on %i engines" % (scale, nengines))
78-
print("%.1f%% of theoretical max" % (100 * scale / nengines))
74+
print(f"{scale:.3f}x parallel performance on {nengines} engines")
75+
print(f"{scale / nengines:.1%} of theoretical max")
7976

8077

8178
if __name__ == '__main__':

docs/source/examples/wave2D/RectPartitioner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def prepare_communication(self):
6161

6262
nsd_ = self.nsd
6363
if nsd_ < 1:
64-
print('Number of space dimensions is %d, nothing to do' % nsd_)
64+
print(f'Number of space dimensions is {nsd_}, nothing to do')
6565
return
6666

6767
self.subd_rank = [-1, -1, -1]
@@ -93,7 +93,7 @@ def prepare_communication(self):
9393
self.subd_rank[1] = (my_id % offsets[2]) / self.num_parts[0]
9494
self.subd_rank[2] = my_id / offsets[2]
9595

96-
print("my_id=%d, subd_rank: " % my_id, self.subd_rank)
96+
print(f"my_id={my_id}, subd_rank={self.subd_rank}")
9797
if my_id == 0:
9898
print("offsets=", offsets)
9999

docs/source/examples/wave2D/communicator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def __init__(self, interface='tcp://*', identity=None):
2727
northport = self.north.bind_to_random_port(interface)
2828
eastport = self.east.bind_to_random_port(interface)
2929

30-
self.north_url = interface + ":%i" % northport
31-
self.east_url = interface + ":%i" % eastport
30+
self.north_url = f"{interface}:{northport}"
31+
self.east_url = f"{interface}:{eastport}"
3232

3333
# guess first public IP from socket
3434
self.location = socket.gethostbyname_ex(socket.gethostname())[-1][0]

0 commit comments

Comments
 (0)