Skip to content

Commit 155f473

Browse files
authored
Replace f-string with "...".format(...) (#146)
Change adding Python 3.5 support.
1 parent 74a9c39 commit 155f473

File tree

1 file changed

+40
-40
lines changed

1 file changed

+40
-40
lines changed

blurb/blurb.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ def sortable_datetime():
163163

164164

165165
def prompt(prompt):
166-
return input(f"[{prompt}> ")
166+
return input("[{}> ".format(prompt))
167167

168168
def require_ok(prompt):
169-
prompt = f"[{prompt}> "
169+
prompt = "[{}> ".format(prompt)
170170
while True:
171171
s = input(prompt).strip()
172172
if s == 'ok':
@@ -393,7 +393,7 @@ def parse(self, text, *, metadata=None, filename="input"):
393393
line_number = None
394394

395395
def throw(s):
396-
raise BlurbError(f"Error in {filename}:{line_number}:\n{s}")
396+
raise BlurbError("Error in {}:{}:\n{}".format(filename, line_number, s))
397397

398398
def finish_entry():
399399
nonlocal body
@@ -473,7 +473,7 @@ def __str__(self):
473473
add_separator = True
474474
if metadata:
475475
for name, value in sorted(metadata.items()):
476-
add(f".. {name}: {value}\n")
476+
add(".. {}: {}\n".format(name, value))
477477
add("\n")
478478
add(textwrap_body(body))
479479
return "".join(output)
@@ -495,10 +495,10 @@ def _parse_next_filename(filename):
495495
components = filename.split("/")
496496
section, filename = components[-2:]
497497
section = unsanitize_section(section)
498-
assert section in sections, f"Unknown section {section}"
498+
assert section in sections, "Unknown section {}".format(section)
499499

500500
fields = [x.strip() for x in filename.split(".")]
501-
assert len(fields) >= 4, f"Can't parse 'next' filename! filename {filename!r} fields {fields}"
501+
assert len(fields) >= 4, "Can't parse 'next' filename! filename {!r} fields {}".format(filename, fields)
502502
assert fields[-1] == "rst"
503503

504504
metadata = {"date": fields[0], "nonce": fields[-2], "section": section}
@@ -647,7 +647,7 @@ def subcommand(fn):
647647
def get_subcommand(subcommand):
648648
fn = subcommands.get(subcommand)
649649
if not fn:
650-
error(f"Unknown subcommand: {subcommand}")
650+
error("Unknown subcommand: {}".format(subcommand))
651651
return fn
652652

653653

@@ -704,19 +704,19 @@ def help(subcommand=None):
704704
for name, p in inspect.signature(fn).parameters.items():
705705
if p.kind == inspect.Parameter.KEYWORD_ONLY:
706706
short_option = name[0]
707-
options.append(f" [-{short_option}|--{name}]")
707+
options.append(" [-{}|--{}]".format(short_option, name))
708708
elif p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD:
709709
positionals.append(" ")
710710
has_default = (p.default != inspect._empty)
711711
if has_default:
712712
positionals.append("[")
713713
nesting += 1
714-
positionals.append(f"<{name}>")
714+
positionals.append("<{}>".format(name))
715715
positionals.append("]" * nesting)
716716

717717

718718
parameters = "".join(options + positionals)
719-
print(f"blurb {subcommand}{parameters}")
719+
print("blurb {}{}".format(subcommand, parameters))
720720
print()
721721
print(doc)
722722
sys.exit(0)
@@ -811,7 +811,7 @@ def init_tmp_with_template():
811811

812812
if failure:
813813
print()
814-
print(f"Error: {failure}")
814+
print("Error: {}".format(failure))
815815
print()
816816
prompt("Hit return to retry (or Ctrl-C to abort)")
817817
print()
@@ -841,20 +841,20 @@ def release(version):
841841
if existing_filenames:
842842
error("Sorry, can't handle appending 'next' files to an existing version (yet).")
843843

844-
output = f"Misc/NEWS.d/{version}.rst"
844+
output = "Misc/NEWS.d/{}.rst".format(version)
845845
filenames = glob_blurbs("next")
846846
blurbs = Blurbs()
847847
date = current_date()
848848

849849
if not filenames:
850-
print(f"No blurbs found. Setting {version} as having no changes.")
851-
body = f"There were no new changes in version {version}.\n"
850+
print("No blurbs found. Setting {} as having no changes.".format(version))
851+
body = "There were no new changes in version {}.\n".format(version)
852852
metadata = {"no changes": "True", "bpo": "0", "section": "Library", "date": date, "nonce": nonceify(body)}
853853
blurbs.append((metadata, body))
854854
else:
855855
no_changes = None
856856
count = len(filenames)
857-
print(f'Merging {count} blurbs to "{output}".')
857+
print('Merging {} blurbs to "{}".'.format(count, output))
858858

859859
for filename in filenames:
860860
if not filename.endswith(".rst"):
@@ -873,9 +873,9 @@ def release(version):
873873
# sanity check: ensuring that saving/reloading the merged blurb file works.
874874
blurbs2 = Blurbs()
875875
blurbs2.load(output)
876-
assert blurbs2 == blurbs, f"Reloading {output} isn't reproducable?!"
876+
assert blurbs2 == blurbs, "Reloading {} isn't reproducable?!".format(output)
877877

878-
print(f"Removing {len(filenames)} 'next' files from git.")
878+
print("Removing {} 'next' files from git.".format(len(filenames)))
879879
git_rm_files.extend(filenames)
880880
flush_git_rm_files()
881881

@@ -948,7 +948,7 @@ def print(*a, sep=" "):
948948
metadata, body = blurbs[0]
949949
release_date = metadata["release date"]
950950

951-
print(f"*Release date: {release_date}*")
951+
print("*Release date: {}*".format(release_date))
952952
print()
953953

954954
if "no changes" in metadata:
@@ -1010,11 +1010,11 @@ def populate():
10101010

10111011
for section in sections:
10121012
dir_name = sanitize_section(section)
1013-
dir_path = f"NEWS.d/next/{dir_name}"
1013+
dir_path = "NEWS.d/next/{}".format(dir_name)
10141014
safe_mkdir(dir_path)
1015-
readme_path = f"NEWS.d/next/{dir_name}/README.rst"
1015+
readme_path = "NEWS.d/next/{}/README.rst".format(dir_name)
10161016
with open(readme_path, "wt", encoding="utf-8") as f:
1017-
f.write(f"Put news entry ``blurb`` files for the *{section}* section in this directory.\n")
1017+
f.write("Put news entry ``blurb`` files for the *{}* section in this directory.\n".format(section))
10181018
git_add_files.append(dir_path)
10191019
git_add_files.append(readme_path)
10201020
flush_git_add_files()
@@ -1025,7 +1025,7 @@ def populate():
10251025
# """
10261026
# Test function for blurb command-line processing.
10271027
# """
1028-
# print(f"arg: boolean {boolean} option {option}")
1028+
# print("arg: boolean {} option {}".format(boolean, option))
10291029

10301030

10311031
@subcommand
@@ -1110,7 +1110,7 @@ def flush_blurb():
11101110
fields.append(field)
11111111
see_also = ", ".join(fields)
11121112
# print("see_also: ", repr(see_also))
1113-
accumulator.append(f"(See also: {see_also})")
1113+
accumulator.append("(See also: {})".format(see_also))
11141114
see_also = None
11151115
if not accumulator:
11161116
return
@@ -1156,8 +1156,8 @@ def flush_version():
11561156
if version is None:
11571157
assert not blurbs, "version should only be None initially, we shouldn't have blurbs yet"
11581158
return
1159-
assert blurbs, f"No blurbs defined when flushing version {version}!"
1160-
output = f"NEWS.d/{version}.rst"
1159+
assert blurbs, "No blurbs defined when flushing version {}!".format(version)
1160+
output = "NEWS.d/{}.rst".format(version)
11611161

11621162
if released:
11631163
# saving merged blurb file for version, e.g. Misc/NEWS.d/3.7.0a1.rst
@@ -1273,11 +1273,11 @@ def flush_version():
12731273
elif line.startswith("- Issue: #15138: base64.urlsafe_{en,de}code() are now 3-4x faster."):
12741274
line = "- Issue #15138: base64.urlsafe_{en,de}code() are now 3-4x faster."
12751275
elif line.title().startswith(("- Request #", "- Bug #", "- Patch #", "- Patches #")):
1276-
# print(f"FIXING LINE {line_number}: {line!r}")
1276+
# print("FIXING LINE {}: {!r}".format(line_number), line)
12771277
line = "- Issue #" + line.partition('#')[2]
1278-
# print(f"FIXED LINE {line!r}")
1278+
# print("FIXED LINE {!r}".format(line))
12791279
# else:
1280-
# print(f"NOT FIXING LINE {line_number}: {line!r}")
1280+
# print("NOT FIXING LINE {}: {!r}".format(line_number, line))
12811281

12821282

12831283
# 4. determine the actual content of the line
@@ -1341,7 +1341,7 @@ def flush_version():
13411341
line = line[4:]
13421342
parse_bpo = True
13431343
else:
1344-
# print(f"[[{line_number:8} no bpo]] {line}")
1344+
# print("[[{:8} no bpo]] {}".format(line_number, line))
13451345
parse_bpo = False
13461346
if parse_bpo:
13471347
# GAAAH
@@ -1381,9 +1381,9 @@ def flush_version():
13811381
try:
13821382
int(bpo) # this will throw if it's not a legal int
13831383
except ValueError:
1384-
sys.exit(f"Couldn't convert bpo number to int on line {line_number}! " + repr(bpo))
1384+
sys.exit("Couldn't convert bpo number to int on line {}! ".format(line_number) + repr(bpo))
13851385
if see_also == "partially":
1386-
sys.exit(f"What the hell on line {line_number}! " + repr(bpo))
1386+
sys.exit("What the hell on line {}! ".format(line_number) + repr(bpo))
13871387

13881388
# 4.6.1 continuation of blurb
13891389
elif line.startswith(" "):
@@ -1392,7 +1392,7 @@ def flush_version():
13921392
elif line.startswith(" * "):
13931393
line = line[3:]
13941394
elif line:
1395-
sys.exit(f"Didn't recognize line {line_number}! " + repr(line))
1395+
sys.exit("Didn't recognize line {}! ".format(line_number) + repr(line))
13961396
# only add blank lines if we have an initial line in the accumulator
13971397
if line or accumulator:
13981398
accumulator.append(line)
@@ -1404,7 +1404,7 @@ def flush_version():
14041404
git_rm_files.append("NEWS")
14051405
flush_git_rm_files()
14061406

1407-
print(f"Wrote {blurb_count} news items across {version_count} versions.")
1407+
print("Wrote {} news items across {} versions.".format(blurb_count, version_count))
14081408
print()
14091409
print("Ready for commit.")
14101410

@@ -1451,10 +1451,10 @@ def main():
14511451
def handle_option(s, dict):
14521452
name = dict.get(s, None)
14531453
if not name:
1454-
sys.exit(f'blurb: Unknown option for {subcommand}: "{s}"')
1454+
sys.exit('blurb: Unknown option for {}: "{}"'.format(subcommand, s))
14551455
kwargs[name] = not kwargs[name]
14561456

1457-
# print(f"short_options {short_options} long_options {long_options}")
1457+
# print("short_options {} long_options {}".format(short_options, long_options))
14581458
for a in args:
14591459
if done_with_options:
14601460
filtered_args.append(a)
@@ -1488,23 +1488,23 @@ def handle_option(s, dict):
14881488
# whoops, must be a real type error, reraise
14891489
raise e
14901490

1491-
how_many = f"{specified} argument"
1491+
how_many = "{} argument".format(specified)
14921492
if specified != 1:
14931493
how_many += "s"
14941494

14951495
if total == 0:
14961496
middle = "accepts no arguments"
14971497
else:
14981498
if total == required:
1499-
middle = f"requires"
1499+
middle = "requires"
15001500
else:
15011501
plural = "" if required == 1 else "s"
1502-
middle = f"requires at least {required} argument{plural} and at most"
1503-
middle += f" {total} argument"
1502+
middle = "requires at least {} argument{} and at most".format(required, plural)
1503+
middle += " {} argument".format(total)
15041504
if total != 1:
15051505
middle += "s"
15061506

1507-
print(f'Error: Wrong number of arguments!\n\nblurb {subcommand} {middle},\nand you specified {how_many}.')
1507+
print('Error: Wrong number of arguments!\n\nblurb {} {},\nand you specified {}.'.format(subcommand, middle, how_many))
15081508
print()
15091509
print("usage: ", end="")
15101510
help(subcommand)

0 commit comments

Comments
 (0)