Skip to content

Commit 9efccb7

Browse files
committed
replace .format by f-strings if applicable
f-strings is faster, than `str().format`
1 parent 7f0e45d commit 9efccb7

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

ipykernel/debugger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ async def richInspectVariables(self, message):
540540
else:
541541
# The code has stopped on a breakpoint, we use the setExpression
542542
# request to get the rich representation of the variable
543-
code = "get_ipython().display_formatter.format(" + var_name + ")"
543+
code = f"get_ipython().display_formatter.format({var_name})"
544544
frame_id = message["arguments"]["frameId"]
545545
seq = message["seq"]
546546
reply = await self._forward_message(

ipykernel/iostream.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ def __getattr__(self, attr):
253253
super().__getattr__(attr)
254254
if hasattr(self.io_thread.socket, attr):
255255
warnings.warn(
256-
"Accessing zmq Socket attribute {attr} on BackgroundSocket"
257-
" is deprecated since ipykernel 4.3.0"
258-
" use .io_thread.socket.{attr}".format(attr=attr),
256+
f"Accessing zmq Socket attribute {attr} on BackgroundSocket"
257+
f" is deprecated since ipykernel 4.3.0"
258+
f" use .io_thread.socket.{attr}",
259259
DeprecationWarning,
260260
stacklevel=2,
261261
)
@@ -267,9 +267,9 @@ def __setattr__(self, attr, value):
267267
super().__setattr__(attr, value)
268268
else:
269269
warnings.warn(
270-
"Setting zmq Socket attribute {attr} on BackgroundSocket"
271-
" is deprecated since ipykernel 4.3.0"
272-
" use .io_thread.socket.{attr}".format(attr=attr),
270+
f"Setting zmq Socket attribute {attr} on BackgroundSocket"
271+
f" is deprecated since ipykernel 4.3.0"
272+
f" use .io_thread.socket.{attr}",
273273
DeprecationWarning,
274274
stacklevel=2,
275275
)

ipykernel/tests/test_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_async_interrupt(asynclib, request):
5454

5555
flush_channels(KC)
5656
msg_id = KC.execute(
57-
"print('begin'); import {0}; await {0}.sleep(5)".format(asynclib)
57+
f"print('begin'); import {asynclib}; await {asynclib}.sleep(5)"
5858
)
5959
busy = KC.get_iopub_msg(timeout=TIMEOUT)
6060
validate_message(busy, "status", msg_id)

ipykernel/tests/test_debugger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ def test_set_breakpoints(kernel_with_debug):
130130
def test_rich_inspect_not_at_breakpoint(kernel_with_debug):
131131
var_name = "text"
132132
value = "Hello the world"
133-
code = """{0}='{1}'
134-
print({0})
135-
""".format(var_name, value)
133+
code = f"""{var_name}='{value}'
134+
print({var_name})
135+
"""
136136

137137
msg_id = kernel_with_debug.execute(code)
138138
get_reply(kernel_with_debug, msg_id)

ipykernel/zmqshell.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,15 +375,14 @@ def connect_info(self, arg_s):
375375

376376

377377
print (info + '\n')
378-
print ("Paste the above JSON into a file, and connect with:\n"
379-
" $> jupyter <app> --existing <file>\n"
380-
"or, if you are local, you can connect with just:\n"
378+
print (
379+
f"Paste the above JSON into a file, and connect with:\n"
380+
f" $> jupyter <app> --existing <file>\n"
381+
f"or, if you are local, you can connect with just:\n"
381382
f" $> jupyter <app> --existing {connection_file}\n"
382-
"or even just:\n"
383-
" $> jupyter <app> --existing\n"
384-
"if this is the most recent Jupyter kernel you have started.".format(
385-
connection_file
386-
)
383+
f"or even just:\n"
384+
f" $> jupyter <app> --existing\n"
385+
f"if this is the most recent Jupyter kernel you have started."
387386
)
388387

389388
@line_magic

0 commit comments

Comments
 (0)