Skip to content

Commit c5a5b49

Browse files
Use f-strings instead of %-style formatting.
1 parent 012bfc9 commit c5a5b49

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

examples/asyncio-python-embed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def print_counter() -> None:
2525
Coroutine that prints counters and saves it in a global variable.
2626
"""
2727
while True:
28-
print("Counter: %i" % counter[0])
28+
print(f"Counter: {counter[0]}")
2929
counter[0] += 1
3030
await asyncio.sleep(3)
3131

examples/asyncio-ssh-python-embed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ async def main(port: int = 8222) -> None:
4444
def create_server() -> MySSHServer:
4545
return MySSHServer(lambda: environ)
4646

47-
print("Listening on :%i" % port)
48-
print('To connect, do "ssh localhost -p %i"' % port)
47+
print(f"Listening on: {port}")
48+
print(f'To connect, do "ssh localhost -p {port}"')
4949

5050
await asyncssh.create_server(
5151
create_server, "", port, server_host_keys=["/etc/ssh/ssh_host_dsa_key"]

ptpython/layout.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def append_category(category: OptionCategory[Any]) -> None:
108108
tokens.extend(
109109
[
110110
("class:sidebar", " "),
111-
("class:sidebar.title", " %-36s" % category.title),
111+
("class:sidebar.title", f" {category.title:36}"),
112112
("class:sidebar", "\n"),
113113
]
114114
)
@@ -130,7 +130,7 @@ def goto_next(mouse_event: MouseEvent) -> None:
130130
sel = ",selected" if selected else ""
131131

132132
tokens.append(("class:sidebar" + sel, " >" if selected else " "))
133-
tokens.append(("class:sidebar.label" + sel, "%-24s" % label, select_item))
133+
tokens.append(("class:sidebar.label" + sel, f"{label:24}", select_item))
134134
tokens.append(("class:sidebar.status" + sel, " ", select_item))
135135
tokens.append(("class:sidebar.status" + sel, f"{status}", goto_next))
136136

@@ -332,7 +332,7 @@ def get_continuation(
332332
width: int, line_number: int, is_soft_wrap: bool
333333
) -> StyleAndTextTuples:
334334
if python_input.show_line_numbers and not is_soft_wrap:
335-
text = ("%i " % (line_number + 1)).rjust(width)
335+
text = f"{line_number + 1} ".rjust(width)
336336
return [("class:line-number", text)]
337337
else:
338338
return to_formatted_text(get_prompt_style().in2_prompt(width))
@@ -368,8 +368,7 @@ def get_text_fragments() -> StyleAndTextTuples:
368368
append(
369369
(
370370
TB,
371-
"%i/%i "
372-
% (python_buffer.working_index + 1, len(python_buffer._working_lines)),
371+
f"{python_buffer.working_index + 1}/{len(python_buffer._working_lines)} ",
373372
)
374373
)
375374

@@ -492,8 +491,7 @@ def toggle_sidebar(mouse_event: MouseEvent) -> None:
492491
("class:status-toolbar", " - "),
493492
(
494493
"class:status-toolbar.python-version",
495-
"%s %i.%i.%i"
496-
% (platform.python_implementation(), version[0], version[1], version[2]),
494+
f"{platform.python_implementation()} {version[0]}.{version[1]}.{version[2]}",
497495
),
498496
("class:status-toolbar", " "),
499497
]

ptpython/printer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import sys
43
import traceback
54
from dataclasses import dataclass
65
from enum import Enum

ptpython/repl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ async def eval_async(self, line: str) -> object:
362362

363363
def _store_eval_result(self, result: object) -> None:
364364
locals: dict[str, Any] = self.get_locals()
365-
locals["_"] = locals["_%i" % self.current_statement_index] = result
365+
locals["_"] = locals[f"_{self.current_statement_index}"] = result
366366

367367
def get_compiler_flags(self) -> int:
368368
return super().get_compiler_flags() | PyCF_ALLOW_TOP_LEVEL_AWAIT

0 commit comments

Comments
 (0)