Skip to content

Commit 368df1c

Browse files
committed
Switch entirely off of the implicit-format() message signature, to finally stop the 'panic when an f-string gets some curly braces in it' errors.
1 parent 4011944 commit 368df1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+346
-898
lines changed

bikeshed/Spec.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,10 @@ def initializeState(self):
117117
if inputContent.date is not None:
118118
self.mdBaseline.addParsedData("Date", inputContent.date)
119119
except FileNotFoundError:
120-
die(
121-
"Couldn't find the input file at the specified location '{0}'.",
122-
self.inputSource,
123-
)
120+
die(f"Couldn't find the input file at the specified location '{self.inputSource}'.")
124121
return False
125122
except OSError:
126-
die("Couldn't open the input file '{0}'.", self.inputSource)
123+
die(f"Couldn't open the input file '{self.inputSource}'.")
127124
return False
128125

129126
return True
@@ -304,7 +301,7 @@ def serialize(self):
304301
try:
305302
rendered = h.Serializer(self.md.opaqueElements, self.md.blockElements).serialize(self.document)
306303
except Exception as e:
307-
die("{0}", e)
304+
die(str(e))
308305
return
309306
rendered = finalHackyCleanup(rendered)
310307
return rendered
@@ -334,11 +331,7 @@ def finish(self, outputFilename=None, newline=None):
334331
with open(outputFilename, "w", encoding="utf-8", newline=newline) as f:
335332
f.write(rendered)
336333
except Exception as e:
337-
die(
338-
"Something prevented me from saving the output document to {0}:\n{1}",
339-
outputFilename,
340-
e,
341-
)
334+
die(f"Something prevented me from saving the output document to {outputFilename}:\n{e}")
342335

343336
def printResultMessage(self):
344337
# If I reach this point, I've succeeded, but maybe with reservations.
@@ -351,7 +344,7 @@ def printResultMessage(self):
351344
success("Successfully generated, but fatal errors were suppressed")
352345
return
353346
if links:
354-
success("Successfully generated, with {0} linking errors", links)
347+
success(f"Successfully generated, with {links} linking errors")
355348
return
356349
if warnings:
357350
success("Successfully generated, with warnings")
@@ -416,7 +409,7 @@ def log_message(self, format, *args):
416409
thread.join()
417410
sys.exit(0)
418411
except Exception as e:
419-
die("Something went wrong while watching the file:\n{0}", e)
412+
die(f"Something went wrong while watching the file:\n{e}")
420413

421414
def fixText(self, text, moreMacros={}):
422415
# Do several textual replacements that need to happen *before* the document is parsed as h.

bikeshed/biblio.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def processReferBiblioFile(lines, storage, order):
223223
if match:
224224
letter, value = match.groups()
225225
else:
226-
die("Biblio line in unexpected format:\n{0}", line)
226+
die(f"Biblio line in unexpected format:\n{line}")
227227
continue
228228

229229
if letter in singularReferCodes:
@@ -233,7 +233,7 @@ def processReferBiblioFile(lines, storage, order):
233233
elif letter in unusedReferCodes:
234234
pass
235235
else:
236-
die("Unknown line type ")
236+
die(f"Unknown line type {letter}:\n{line}")
237237
if biblio is not None:
238238
storage[biblio["linkText"].lower()] = biblio
239239
return storage
@@ -277,7 +277,7 @@ def processSpecrefBiblioFile(text, storage, order):
277277
try:
278278
datas = json.loads(text)
279279
except Exception as e:
280-
die("Couldn't read the local JSON file:\n{0}", str(e))
280+
die(f"Couldn't read the local JSON file:\n{e}")
281281
return storage
282282

283283
# JSON field name: BiblioEntry name
@@ -372,7 +372,7 @@ def loadBiblioDataFile(lines, storage):
372372
}
373373
line = next(lines) # Eat the -
374374
else:
375-
die("Unknown biblio prefix '{0}' on key '{1}'", prefix, fullKey)
375+
die(f"Unknown biblio prefix '{prefix}' on key '{fullKey}'")
376376
continue
377377
storage[key].append(b)
378378
except StopIteration:

bikeshed/boilerplate.py

+8-18
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,7 @@ def addExplicitIndexes(doc):
359359
status = el.get("status")
360360
if status and status not in config.specStatuses:
361361
die(
362-
"<index> has unknown value '{0}' for status. Must be {1}.",
363-
status,
364-
config.englishFromList(config.specStatuses),
362+
f"<index> has unknown value '{status}' for status. Must be {config.englishFromList(config.specStatuses)}.",
365363
el=el,
366364
)
367365
continue
@@ -371,7 +369,7 @@ def addExplicitIndexes(doc):
371369
for t in types:
372370
if t not in config.dfnTypes:
373371
die(
374-
"Unknown type value '{}' on {}".format(t, outerHTML(el)),
372+
f"Unknown type value '{t}' on {outerHTML(el)}",
375373
el=el,
376374
)
377375
types.remove(t)
@@ -383,7 +381,7 @@ def addExplicitIndexes(doc):
383381
specs = {x.strip() for x in el.get("data-link-spec").split(",")}
384382
for s in list(specs):
385383
if s not in doc.refs.specs:
386-
die("Unknown spec name '{}' on {}".format(s, outerHTML(el)), el=el)
384+
die(f"Unknown spec name '{s}' on {outerHTML(el)}", el=el)
387385
specs.remove(s)
388386
else:
389387
specs = None
@@ -401,7 +399,7 @@ def addExplicitIndexes(doc):
401399
export = False
402400
else:
403401
die(
404-
"Unknown export value '{}' (should be boolish) on {}".format(exportVal, outerHTML(el)),
402+
f"Unknown export value '{exportVal}' (should be boolish) on {outerHTML(el)}",
405403
el=el,
406404
)
407405
export = None
@@ -599,8 +597,7 @@ def extractKeyValFromRow(row, table):
599597
result = re.match(r"(.*):", textContent(row[0]).strip())
600598
if result is None:
601599
die(
602-
"Propdef row headers must be a word followed by a colon. Got:\n{0}",
603-
textContent(row[0]).strip(),
600+
f"Propdef row headers must be a word followed by a colon. Got:\n{textContent(row[0]).strip()}",
604601
el=table,
605602
)
606603
return "", ""
@@ -802,20 +799,14 @@ def addTOCSection(doc):
802799
if isinstance(container, int):
803800
# Saw a low-level heading without first seeing a higher heading.
804801
die(
805-
"Saw an <h{0}> without seeing an <h{1}> first. Please order your headings properly.\n{2}",
806-
level,
807-
level - 1,
808-
outerHTML(header),
802+
f"Saw an <h{level}> without seeing an <h{level-1}> first. Please order your headings properly.\n{outerHTML(header)}",
809803
el=header,
810804
)
811805
return
812806
if level > previousLevel + 1:
813807
# Jumping two levels is a no-no.
814808
die(
815-
"Heading level jumps more than one level, from h{0} to h{1}:\n {2}",
816-
previousLevel,
817-
level,
818-
textContent(header).replace("\n", " "),
809+
f"Heading level jumps more than one level, from h{previousLevel} to h{level}:\n{outerHTML(el)}",
819810
el=header,
820811
)
821812
return
@@ -920,8 +911,7 @@ def printTranslation(tr):
920911
missingInfo = True
921912
if missingInfo:
922913
warn(
923-
"Bikeshed doesn't have all the translation info for '{0}'. Please add to bikeshed/spec-data/readonly/languages.json and submit a PR!",
924-
lang,
914+
f"Bikeshed doesn't have all the translation info for '{lang}'. Please add to bikeshed/spec-data/readonly/languages.json and submit a PR!"
925915
)
926916
if nativeName:
927917
return E.span(

bikeshed/caniuse.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def addCanIUsePanels(doc):
3333

3434
featId = featId.lower()
3535
if not doc.canIUse.hasFeature(featId):
36-
die("Unrecognized Can I Use feature ID: {0}", featId, el=dfn)
36+
die(f"Unrecognized Can I Use feature ID: {featId}", el=dfn)
3737
feature = doc.canIUse.getFeature(featId)
3838

3939
addClass(dfn, "caniuse-paneled")
@@ -45,11 +45,7 @@ def addCanIUsePanels(doc):
4545
)
4646
dfnId = dfn.get("id")
4747
if not dfnId:
48-
die(
49-
"Elements with `caniuse` attribute need to have an ID as well. Got:\n{0}",
50-
serializeTag(dfn),
51-
el=dfn,
52-
)
48+
die(f"Elements with `caniuse` attribute need to have an ID as well. Got:\n{serializeTag(dfn)}", el=dfn)
5349
continue
5450
panel.set("data-dfn-id", dfnId)
5551
appendChild(doc.body, panel)
@@ -207,9 +203,9 @@ def validateCanIUseURLs(doc, elements):
207203

208204
unusedFeatures = urlFeatures - docFeatures
209205
if unusedFeatures:
206+
featureList = "\n".join(" * {0} - https://caniuse.com/#feat={0}".format(x) for x in sorted(unusedFeatures))
210207
warn(
211-
"The following Can I Use features are associated with your URLs, but don't show up in your spec:\n{0}",
212-
"\n".join(" * {0} - https://caniuse.com/#feat={0}".format(x) for x in sorted(unusedFeatures)),
208+
f"The following Can I Use features are associated with your URLs, but don't show up in your spec:\n{featureList}"
213209
)
214210

215211

bikeshed/config/retrieve.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,9 @@ def boilerplatePath(*segs):
107107
for f in (statusFile, genericFile):
108108
if doc.inputSource.cheaplyExists(f):
109109
warn(
110-
(
111-
"Found {0} next to the specification without a matching\n"
112-
+ "Local Boilerplate: {1} yes\n"
113-
+ "in the metadata. This include won't be found when building via a URL."
114-
).format(f, name)
110+
f"Found {f} next to the specification without a matching\n"
111+
+ f"Local Boilerplate: {name} yes\n"
112+
+ "in the metadata. This include won't be found when building via a URL."
115113
)
116114
# We should remove this after giving specs time to react to the warning:
117115
sources.append(doc.inputSource.relative(f))
@@ -138,9 +136,6 @@ def boilerplatePath(*segs):
138136
else:
139137
if error:
140138
die(
141-
"Couldn't find an appropriate include file for the {0} inclusion, given group='{1}' and status='{2}'.",
142-
name,
143-
group,
144-
status,
139+
f"Couldn't find an appropriate include file for the {name} inclusion, given group='{group}' and status='{status}'."
145140
)
146141
return ""

bikeshed/config/status.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ def canonicalizeStatus(rawStatus, group):
295295

296296
def validateW3Cstatus(group, status, rawStatus):
297297
if status == "DREAM":
298-
warn("You used Status: DREAM for a W3C document." + " Consider UD instead.")
298+
warn("You used Status: DREAM for a W3C document. Consider UD instead.")
299299
return
300300

301301
if "w3c/" + status in shortToLongStatus:
@@ -304,25 +304,17 @@ def validateW3Cstatus(group, status, rawStatus):
304304
def formatStatusSet(statuses):
305305
return ", ".join(sorted({status.split("/")[-1] for status in statuses}))
306306

307-
msg = "You used Status: {0}, but {1} limited to these statuses: {2}."
308-
309307
if group in w3cIgs and status not in w3cIGStatuses:
310308
warn(
311-
msg,
312-
rawStatus,
313-
"W3C Interest Groups are",
314-
formatStatusSet(w3cIGStatuses),
309+
f"You used Status: {rawStatus}, but W3C Interest Groups are limited to these statuses: {formatStatusSet(w3cIGStatuses)}."
315310
)
316311

317312
if group == "tag" and status not in w3cTAGStatuses:
318313
warn(msg, rawStatus, "the TAG is", formatStatusSet(w3cTAGStatuses))
319314

320315
if group in w3cCgs and status not in w3cCommunityStatuses:
321316
warn(
322-
msg,
323-
rawStatus,
324-
"W3C Community and Business Groups are",
325-
formatStatusSet(w3cCommunityStatuses),
317+
f"You used Status: {rawStatus}, but W3C Community and Business Groups are limited to these statuses: {formatStatusSet(w3cCommunityStatuses)}."
326318
)
327319

328320
def megaGroupsForStatus(status):
@@ -380,9 +372,7 @@ def megaGroupsForStatus(status):
380372
)
381373
else:
382374
if len(possibleMgs) == 1:
383-
msg += " That status can only be used with the org '{0}', like `Status: {0}/{1}`".format(
384-
possibleMgs[0], status
385-
)
375+
msg += f" That status can only be used with the org '{possibleMgs[0]}', like `Status: {possibleMgs[0]}/{status}`"
386376
else:
387377
msg += " That status can only be used with the orgs {}.".format(
388378
englishFromList(f"'{x}'" for x in possibleMgs)
@@ -393,7 +383,7 @@ def megaGroupsForStatus(status):
393383
msg = f"Unknown Status metadata '{canonStatus}'. Check the docs for valid Status values."
394384
else:
395385
msg = f"Status '{status}' can't be used with the org '{megaGroup}'. Check the docs for valid Status values."
396-
die("{0}", msg)
386+
die(msg)
397387
return canonStatus
398388

399389
# Otherwise, they provided a bare status.
@@ -425,7 +415,7 @@ def megaGroupsForStatus(status):
425415
msg += ", and you don't have a Group metadata. Please declare your Group, or check the docs for statuses that can be used by anyone."
426416
else:
427417
msg = f"Unknown Status metadata '{canonStatus}'. Check the docs for valid Status values."
428-
die("{0}", msg)
418+
die(msg)
429419
return canonStatus
430420

431421

0 commit comments

Comments
 (0)