Skip to content

Commit deceac6

Browse files
committed
Convert all remaining s-string to f-string
1 parent bd9a0e4 commit deceac6

11 files changed

Lines changed: 56 additions & 66 deletions

File tree

lobster/common/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def lobster_read(
101101
mh.error(loc, f"unknown schema kind {data['schema']}")
102102
if data["version"] not in supported_schema[data["schema"]]:
103103
mh.error(loc,
104-
"version %u for schema %s is not supported" %
105-
(data["version"], data["schema"]))
104+
f"version {data['version']} for schema "
105+
f"{data['schema']} is not supported")
106106

107107
duplicate_items = []
108108
# Convert to items, and integrate into symbol table

lobster/common/items.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def determine_status(self, config, stab):
161161
if not any(has_trace[src] for src in chain) and \
162162
not has_just_down:
163163
ok_down = False
164-
self.messages.append("missing reference to %s" %
165-
" or ".join(sorted(chain)))
164+
chain_str = " or ".join(sorted(chain))
165+
self.messages.append(f"missing reference to {chain_str}")
166166

167167
# Set status
168168
if self.has_error:

lobster/common/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def parse(self):
8383
else:
8484
self.error(self.nt.loc,
8585
"expected: requirements|implementation|activity,"
86-
" found %s instead" % self.nt.value())
86+
f" found {self.nt.value()} instead")
8787

8888
return self.levels
8989

lobster/common/report.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,13 @@ def resolve_references_for_items(self):
9090
# Check versions match, if specified
9191
if dst_tag.version is not None:
9292
if dst_item.tag.version is None:
93-
src_item.error("tracing destination %s is unversioned"
94-
% dst_tag.key())
93+
src_item.error(
94+
f"tracing destination {dst_tag.key()} is unversioned"
95+
)
9596
elif dst_tag.version != dst_item.tag.version:
96-
src_item.error("tracing destination %s has version %s"
97-
" (expected %s)" %
98-
(dst_tag.key(),
99-
dst_item.tag.version,
100-
dst_tag.version))
97+
msg = (f"tracing destination {dst_tag.key()} has version "
98+
f"{dst_item.tag.version} (expected {dst_tag.version})")
99+
src_item.error(msg)
101100

102101
def compute_coverage_for_items(self):
103102
for level_obj in self.coverage.values():
@@ -237,8 +236,8 @@ def validate_indicated_schema(self, data, loc):
237236
self.mh.error(loc, f"unknown schema kind {data['schema']}")
238237
if data["version"] not in supported_schema[data["schema"]]:
239238
self.mh.error(loc,
240-
"version %u for schema %s is not supported" %
241-
(data["version"], data["schema"]))
239+
f"version {data['version']} for schema "
240+
f"{data['schema']} is not supported")
242241

243242
def validate_basic_structure_of_lobster_file(self, data, loc):
244243
"""

lobster/htmldoc/htmldoc.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ def generate(self, doc) -> List[str]:
129129
}
130130

131131
rv = ['<div class="dropdown">']
132-
rv.append('<button class="dropbtn">%s%s</button>' %
133-
(html.escape(self.name),
134-
'<svg class="icon"><use href="#svg-chevron-down"></use></svg>'))
132+
rv.append(
133+
f'<button class="dropbtn">{html.escape(self.name)}'
134+
'<svg class="icon"><use href="#svg-chevron-down"></use></svg>'
135+
'</button>'
136+
)
135137
rv.append('<div class="dropdown-content">')
136138
for item in self.items:
137139
rv += item.generate(doc)

lobster/tools/codebeamer/codebeamer.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ def get_many_items(cb_config: Config, item_ids: Iterable[int]):
200200
f"({','.join(str(item_id) for item_id in item_ids)})")
201201

202202
while True:
203-
base_url = "%s/items/query?page=%u&pageSize=%u&queryString=%s"\
204-
% (cb_config.base, page_id,
205-
cb_config.page_size, query_string)
203+
base_url = (f"{cb_config.base}/items/query?page={page_id}"
204+
f"&pageSize={cb_config.page_size}"
205+
f"&queryString={query_string}")
206206
data = query_cb_single(cb_config, base_url)
207207
rv += data["items"]
208208
if len(rv) == data["total"]:
@@ -224,19 +224,13 @@ def get_query(cb_config: Config, query: Union[int, str]):
224224
total_items = None
225225

226226
while total_items is None or len(rv) < total_items:
227-
print("Fetching page %u of query..." % page_id)
227+
print(f"Fetching page {page_id} of query...")
228228
if isinstance(query, int):
229-
url = ("%s/reports/%u/items?page=%u&pageSize=%u" %
230-
(cb_config.base,
231-
query,
232-
page_id,
233-
cb_config.page_size))
229+
url = (f"{cb_config.base}/reports/{query}/items"
230+
f"?page={page_id}&pageSize={cb_config.page_size}")
234231
elif isinstance(query, str):
235-
url = ("%s/items/query?page=%u&pageSize=%u&queryString=%s" %
236-
(cb_config.base,
237-
page_id,
238-
cb_config.page_size,
239-
query))
232+
url = (f"{cb_config.base}/items/query?page={page_id}"
233+
f"&pageSize={cb_config.page_size}&queryString={query}")
240234
data = query_cb_single(cb_config, url)
241235
if len(data) != 4:
242236
raise MismatchException(

lobster/tools/core/html_report/html_report.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,18 @@ def create_item_coverage(doc, report):
151151
doc.add_line(
152152
f'<tr class="coverage-table-{level.name.replace(" ", "-").lower()}">'
153153
)
154-
doc.add_line('<td><a href="#sec-%s">%s</a></td>' %
155-
(name_hash(level.name),
156-
html.escape(level.name)))
154+
doc.add_line(
155+
f'<td><a href="#sec-{name_hash(level.name)}">'
156+
f'{html.escape(level.name)}</a></td>'
157+
)
157158
doc.add_line(f"<td>{data.coverage:.1f}%</td>")
158159
doc.add_line("<td>")
159-
doc.add_line('<progress value="%u" max="%u">' %
160-
(data.ok, data.items))
160+
doc.add_line(f'<progress value="{data.ok}" max="{data.items}">')
161161
doc.add_line(f"{data.coverage:.2f}%")
162162
doc.add_line('</progress>')
163163
doc.add_line("</td>")
164-
doc.add_line('<td align="right">%u</td>' % data.ok)
165-
doc.add_line('<td align="right">%u</td>' % data.items)
164+
doc.add_line(f'<td align="right">{data.ok}</td>')
165+
doc.add_line(f'<td align="right">{data.items}</td>')
166166
doc.add_line("</tr>")
167167
doc.add_line("</table>")
168168

@@ -205,12 +205,13 @@ def write_item_box_begin(doc, item, report):
205205
doc.add_line(f'<div class="item-{html.escape(item.tracing_status.name.lower())}" '
206206
f'id="item-{item.tag.hash()}">')
207207

208-
doc.add_line('<div class="item-name">%s %s</div>' %
209-
('<svg class="icon"><use href="#svg-check-square"></use></svg>'
210-
if item.tracing_status in (Tracing_Status.OK,
211-
Tracing_Status.JUSTIFIED)
212-
else '<svg class="icon"><use href="#svg-alert-triangle"></use></svg>',
213-
xref_item(item, link=False)))
208+
svg_icon = (
209+
'<svg class="icon"><use href="#svg-check-square"></use></svg>'
210+
if item.tracing_status in (Tracing_Status.OK, Tracing_Status.JUSTIFIED)
211+
else '<svg class="icon"><use href="#svg-alert-triangle"></use></svg>'
212+
)
213+
item_name = f'{svg_icon} {xref_item(item, link=False)}'
214+
doc.add_line(f'<div class="item-name">{item_name}</div>')
214215

215216
doc.add_line('<div class="attribute">Source: ')
216217
doc.add_line('<svg class="icon"><use href="#svg-external-link"></use></svg>')
@@ -533,9 +534,10 @@ def write_html(report, dot, high_contrast, render_md) -> str:
533534
Github_Reference)):
534535
new_file_heading = item.location.filename
535536
elif isinstance(item.location, Codebeamer_Reference):
536-
new_file_heading = "Codebeamer %s, tracker %u" % \
537-
(item.location.cb_root,
538-
item.location.tracker)
537+
new_file_heading = (
538+
f"Codebeamer {item.location.cb_root},"
539+
f" tracker {item.location.tracker}"
540+
)
539541
else: # pragma: no cover
540542
assert False
541543
if new_file_heading != file_heading:

lobster/tools/cpptest/constants.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ def __init__(self, codebeamer_url = ''):
66

77
self.codebeamer_link = codebeamer_url + "/issue/"
88
self.requirement = re.compile(r'@requirement[\s\S]*?(?=@|\Z)')
9-
self.requirement_tag_http = ((r"([@\\]requirement(\s+"
10-
r"(CB-#\d+\s+)*({}\d+\s*,?\s*/*\*?)+)+)")
11-
.format(self.codebeamer_link))
9+
self.requirement_tag_http = (
10+
rf"([@\\]requirement(\s+(CB-#\d+\s+)*"
11+
rf"({self.codebeamer_link}\d+\s*,?\s*/*\*?)+)+)"
12+
)
1213
self.requirement_tag_http_named = rf"({self.codebeamer_link}(?P<number>\d+))"
1314

1415
NON_EXISTING_INFO = "---"

lobster/tools/python/python.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,12 @@ def lobster_tag(self):
155155

156156
def warn_ignored(self, reason):
157157
for tag in self.tags:
158-
print("%s: warning: ignored tag %s because "
159-
"%s already has annotations" %
160-
(self.location.to_string(),
161-
tag,
162-
reason))
158+
print(f"{self.location.to_string()}: warning: ignored tag {tag}"
159+
f" because {reason} already has annotations")
163160
for just in self.just:
164-
print("%s: warning: ignored justification '%s' because "
165-
"%s already has annotations" %
166-
(self.location.to_string(),
167-
just,
168-
reason))
161+
print(f"{self.location.to_string()}: warning: "
162+
f"ignored justification '{just}' "
163+
f"because {reason} already has annotations")
169164

170165

171166
class Python_Module(Python_Traceable_Node):

pylint3.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ disable=
1010
too-many-arguments,
1111
too-many-locals,
1212
too-many-statements,
13-
too-many-nested-blocks,
14-
consider-using-f-string
13+
too-many-nested-blocks
1514

1615
[REPORTS]
1716
output-format=text

0 commit comments

Comments
 (0)