Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace f-string with "...".format(...) #146

Merged
merged 1 commit into from Jun 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
80 changes: 40 additions & 40 deletions blurb/blurb.py
Expand Up @@ -163,10 +163,10 @@ def sortable_datetime():


def prompt(prompt):
return input(f"[{prompt}> ")
return input("[{}> ".format(prompt))

def require_ok(prompt):
prompt = f"[{prompt}> "
prompt = "[{}> ".format(prompt)
while True:
s = input(prompt).strip()
if s == 'ok':
Expand Down Expand Up @@ -393,7 +393,7 @@ def parse(self, text, *, metadata=None, filename="input"):
line_number = None

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

def finish_entry():
nonlocal body
Expand Down Expand Up @@ -473,7 +473,7 @@ def __str__(self):
add_separator = True
if metadata:
for name, value in sorted(metadata.items()):
add(f".. {name}: {value}\n")
add(".. {}: {}\n".format(name, value))
add("\n")
add(textwrap_body(body))
return "".join(output)
Expand All @@ -495,10 +495,10 @@ def _parse_next_filename(filename):
components = filename.split("/")
section, filename = components[-2:]
section = unsanitize_section(section)
assert section in sections, f"Unknown section {section}"
assert section in sections, "Unknown section {}".format(section)

fields = [x.strip() for x in filename.split(".")]
assert len(fields) >= 4, f"Can't parse 'next' filename! filename {filename!r} fields {fields}"
assert len(fields) >= 4, "Can't parse 'next' filename! filename {!r} fields {}".format(filename, fields)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is surely longer than 79 characters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PEP 8 allows up to 120 characters. The file already contains lines longer than 120 characters (before my change) ;-)

assert fields[-1] == "rst"

metadata = {"date": fields[0], "nonce": fields[-2], "section": section}
Expand Down Expand Up @@ -647,7 +647,7 @@ def subcommand(fn):
def get_subcommand(subcommand):
fn = subcommands.get(subcommand)
if not fn:
error(f"Unknown subcommand: {subcommand}")
error("Unknown subcommand: {}".format(subcommand))
return fn


Expand Down Expand Up @@ -704,19 +704,19 @@ def help(subcommand=None):
for name, p in inspect.signature(fn).parameters.items():
if p.kind == inspect.Parameter.KEYWORD_ONLY:
short_option = name[0]
options.append(f" [-{short_option}|--{name}]")
options.append(" [-{}|--{}]".format(short_option, name))
elif p.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD:
positionals.append(" ")
has_default = (p.default != inspect._empty)
if has_default:
positionals.append("[")
nesting += 1
positionals.append(f"<{name}>")
positionals.append("<{}>".format(name))
positionals.append("]" * nesting)


parameters = "".join(options + positionals)
print(f"blurb {subcommand}{parameters}")
print("blurb {}{}".format(subcommand, parameters))
print()
print(doc)
sys.exit(0)
Expand Down Expand Up @@ -811,7 +811,7 @@ def init_tmp_with_template():

if failure:
print()
print(f"Error: {failure}")
print("Error: {}".format(failure))
print()
prompt("Hit return to retry (or Ctrl-C to abort)")
print()
Expand Down Expand Up @@ -841,20 +841,20 @@ def release(version):
if existing_filenames:
error("Sorry, can't handle appending 'next' files to an existing version (yet).")

output = f"Misc/NEWS.d/{version}.rst"
output = "Misc/NEWS.d/{}.rst".format(version)
filenames = glob_blurbs("next")
blurbs = Blurbs()
date = current_date()

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

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

print(f"Removing {len(filenames)} 'next' files from git.")
print("Removing {} 'next' files from git.".format(len(filenames)))
git_rm_files.extend(filenames)
flush_git_rm_files()

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

print(f"*Release date: {release_date}*")
print("*Release date: {}*".format(release_date))
print()

if "no changes" in metadata:
Expand Down Expand Up @@ -1010,11 +1010,11 @@ def populate():

for section in sections:
dir_name = sanitize_section(section)
dir_path = f"NEWS.d/next/{dir_name}"
dir_path = "NEWS.d/next/{}".format(dir_name)
safe_mkdir(dir_path)
readme_path = f"NEWS.d/next/{dir_name}/README.rst"
readme_path = "NEWS.d/next/{}/README.rst".format(dir_name)
with open(readme_path, "wt", encoding="utf-8") as f:
f.write(f"Put news entry ``blurb`` files for the *{section}* section in this directory.\n")
f.write("Put news entry ``blurb`` files for the *{}* section in this directory.\n".format(section))
git_add_files.append(dir_path)
git_add_files.append(readme_path)
flush_git_add_files()
Expand All @@ -1025,7 +1025,7 @@ def populate():
# """
# Test function for blurb command-line processing.
# """
# print(f"arg: boolean {boolean} option {option}")
# print("arg: boolean {} option {}".format(boolean, option))


@subcommand
Expand Down Expand Up @@ -1110,7 +1110,7 @@ def flush_blurb():
fields.append(field)
see_also = ", ".join(fields)
# print("see_also: ", repr(see_also))
accumulator.append(f"(See also: {see_also})")
accumulator.append("(See also: {})".format(see_also))
see_also = None
if not accumulator:
return
Expand Down Expand Up @@ -1156,8 +1156,8 @@ def flush_version():
if version is None:
assert not blurbs, "version should only be None initially, we shouldn't have blurbs yet"
return
assert blurbs, f"No blurbs defined when flushing version {version}!"
output = f"NEWS.d/{version}.rst"
assert blurbs, "No blurbs defined when flushing version {}!".format(version)
output = "NEWS.d/{}.rst".format(version)

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


# 4. determine the actual content of the line
Expand Down Expand Up @@ -1341,7 +1341,7 @@ def flush_version():
line = line[4:]
parse_bpo = True
else:
# print(f"[[{line_number:8} no bpo]] {line}")
# print("[[{:8} no bpo]] {}".format(line_number, line))
parse_bpo = False
if parse_bpo:
# GAAAH
Expand Down Expand Up @@ -1381,9 +1381,9 @@ def flush_version():
try:
int(bpo) # this will throw if it's not a legal int
except ValueError:
sys.exit(f"Couldn't convert bpo number to int on line {line_number}! " + repr(bpo))
sys.exit("Couldn't convert bpo number to int on line {}! ".format(line_number) + repr(bpo))
if see_also == "partially":
sys.exit(f"What the hell on line {line_number}! " + repr(bpo))
sys.exit("What the hell on line {}! ".format(line_number) + repr(bpo))

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

print(f"Wrote {blurb_count} news items across {version_count} versions.")
print("Wrote {} news items across {} versions.".format(blurb_count, version_count))
print()
print("Ready for commit.")

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

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

how_many = f"{specified} argument"
how_many = "{} argument".format(specified)
if specified != 1:
how_many += "s"

if total == 0:
middle = "accepts no arguments"
else:
if total == required:
middle = f"requires"
middle = "requires"
else:
plural = "" if required == 1 else "s"
middle = f"requires at least {required} argument{plural} and at most"
middle += f" {total} argument"
middle = "requires at least {} argument{} and at most".format(required, plural)
middle += " {} argument".format(total)
if total != 1:
middle += "s"

print(f'Error: Wrong number of arguments!\n\nblurb {subcommand} {middle},\nand you specified {how_many}.')
print('Error: Wrong number of arguments!\n\nblurb {} {},\nand you specified {}.'.format(subcommand, middle, how_many))
print()
print("usage: ", end="")
help(subcommand)
Expand Down