Skip to content

Commit 216fc93

Browse files
committed
More f strings!
1 parent 29cd9d8 commit 216fc93

3 files changed

Lines changed: 9 additions & 14 deletions

File tree

Tools/peg_generator/.ruff.toml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,13 @@ extend-exclude = [
66

77
[lint]
88
select = [
9-
"F", # Enable all pyflakes rules
10-
"I", # Enable all isort rules
11-
"UP", # Enable all pyupgrade rules by default
9+
"F", # pyflakes
10+
"I", # isort
11+
"UP", # pyupgrade
1212
"RUF100", # Ban unused `# noqa` comments
1313
"PGH004", # Ban blanket `# noqa` comments (only ignore specific error codes)
1414
]
1515
ignore = [
16-
# Unnecessary parentheses to functools.lru_cache: just leads to unnecessary churn.
17-
# https://github.com/python/cpython/pull/104684#discussion_r1199653347.
18-
"UP011",
19-
# Use format specifiers instead of %-style formatting.
20-
# Doesn't always make code more readable.
21-
"UP031",
22-
# Use f-strings instead of format specifiers.
23-
# Doesn't always make code more readable.
24-
"UP032",
2516
# Use PEP-604 unions rather than tuples for isinstance() checks.
2617
# Makes code slower and more verbose. https://github.com/astral-sh/ruff/issues/7871.
2718
"UP038",

Tools/peg_generator/pegen/ast_dump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ def _format(node: Any, level: int = 0) -> tuple[str, bool]:
6565
return repr(node), True
6666

6767
if all(cls.__name__ != "AST" for cls in node.__class__.__mro__):
68-
raise TypeError("expected AST, got %r" % node.__class__.__name__)
68+
raise TypeError(f"expected AST, got {node.__class__.__name__!r}")
6969
return _format(node)[0]

Tools/peg_generator/pegen/tokenizer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99

1010
def shorttok(tok: tokenize.TokenInfo) -> str:
11-
return "%-25.25s" % f"{tok.start[0]}.{tok.start[1]}: {token.tok_name[tok.type]}:{tok.string!r}"
11+
formatted = (
12+
f"{tok.start[0]}.{tok.start[1]}: "
13+
f"{token.tok_name[tok.type]}:{tok.string!r}"
14+
)
15+
return f"{formatted:<25.25}"
1216

1317

1418
class Tokenizer:

0 commit comments

Comments
 (0)