Skip to content

Commit b97aaf2

Browse files
committed
style: prefer explicit string concatenation
1 parent b5ddfd9 commit b97aaf2

14 files changed

+133
-140
lines changed

coverage/cmdline.py

+30-30
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Opts:
4545
'', '--concurrency', action='store', metavar="LIB",
4646
choices=CONCURRENCY_CHOICES,
4747
help=(
48-
"Properly measure code using a concurrency library. "
48+
"Properly measure code using a concurrency library. " +
4949
"Valid values are: {}."
5050
).format(", ".join(CONCURRENCY_CHOICES)),
5151
)
@@ -77,20 +77,20 @@ class Opts:
7777
'', '--include', action='store',
7878
metavar="PAT1,PAT2,...",
7979
help=(
80-
"Include only files whose paths match one of these patterns. "
80+
"Include only files whose paths match one of these patterns. " +
8181
"Accepts shell-style wildcards, which must be quoted."
8282
),
8383
)
8484
pylib = optparse.make_option(
8585
'-L', '--pylib', action='store_true',
8686
help=(
87-
"Measure coverage even inside the Python installed library, "
87+
"Measure coverage even inside the Python installed library, " +
8888
"which isn't done by default."
8989
),
9090
)
9191
sort = optparse.make_option(
9292
'--sort', action='store', metavar='COLUMN',
93-
help="Sort the report by the named column: name, stmts, miss, branch, brpart, or cover. "
93+
help="Sort the report by the named column: name, stmts, miss, branch, brpart, or cover. " +
9494
"Default is name."
9595
)
9696
show_missing = optparse.make_option(
@@ -117,15 +117,15 @@ class Opts:
117117
'', '--omit', action='store',
118118
metavar="PAT1,PAT2,...",
119119
help=(
120-
"Omit files whose paths match one of these patterns. "
120+
"Omit files whose paths match one of these patterns. " +
121121
"Accepts shell-style wildcards, which must be quoted."
122122
),
123123
)
124124
contexts = optparse.make_option(
125125
'', '--contexts', action='store',
126126
metavar="REGEX1,REGEX2,...",
127127
help=(
128-
"Only display data from lines covered in the given contexts. "
128+
"Only display data from lines covered in the given contexts. " +
129129
"Accepts Python regexes, which must be quoted."
130130
),
131131
)
@@ -146,30 +146,30 @@ class Opts:
146146
parallel_mode = optparse.make_option(
147147
'-p', '--parallel-mode', action='store_true',
148148
help=(
149-
"Append the machine name, process id and random number to the "
150-
".coverage data file name to simplify collecting data from "
149+
"Append the machine name, process id and random number to the " +
150+
".coverage data file name to simplify collecting data from " +
151151
"many processes."
152152
),
153153
)
154154
module = optparse.make_option(
155155
'-m', '--module', action='store_true',
156156
help=(
157-
"<pyfile> is an importable Python module, not a script path, "
157+
"<pyfile> is an importable Python module, not a script path, " +
158158
"to be run as 'python -m' would run it."
159159
),
160160
)
161161
precision = optparse.make_option(
162162
'', '--precision', action='store', metavar='N', type=int,
163163
help=(
164-
"Number of digits after the decimal point to display for "
164+
"Number of digits after the decimal point to display for " +
165165
"reported coverage percentages."
166166
),
167167
)
168168
rcfile = optparse.make_option(
169169
'', '--rcfile', action='store',
170170
help=(
171-
"Specify configuration file. "
172-
"By default '.coveragerc', 'setup.cfg', 'tox.ini', and "
171+
"Specify configuration file. " +
172+
"By default '.coveragerc', 'setup.cfg', 'tox.ini', and " +
173173
"'pyproject.toml' are tried. [env: COVERAGE_RCFILE]"
174174
),
175175
)
@@ -180,7 +180,7 @@ class Opts:
180180
timid = optparse.make_option(
181181
'', '--timid', action='store_true',
182182
help=(
183-
"Use a simpler but slower trace method. Try this if you get "
183+
"Use a simpler but slower trace method. Try this if you get " +
184184
"seemingly impossible results!"
185185
),
186186
)
@@ -328,7 +328,7 @@ def get_prog_name(self):
328328
] + GLOBAL_ARGS,
329329
usage="[options] [modules]",
330330
description=(
331-
"Make annotated copies of the given files, marking statements that are executed "
331+
"Make annotated copies of the given files, marking statements that are executed " +
332332
"with > and statements that are missed with !."
333333
),
334334
),
@@ -341,11 +341,11 @@ def get_prog_name(self):
341341
] + GLOBAL_ARGS,
342342
usage="[options] <path1> <path2> ... <pathN>",
343343
description=(
344-
"Combine data from multiple coverage files collected "
345-
"with 'run -p'. The combined results are written to a single "
346-
"file representing the union of the data. The positional "
347-
"arguments are data files or directories containing data files. "
348-
"If no paths are provided, data files in the default data file's "
344+
"Combine data from multiple coverage files collected " +
345+
"with 'run -p'. The combined results are written to a single " +
346+
"file representing the union of the data. The positional " +
347+
"arguments are data files or directories containing data files. " +
348+
"If no paths are provided, data files in the default data file's " +
349349
"directory are combined."
350350
),
351351
),
@@ -354,12 +354,12 @@ def get_prog_name(self):
354354
"debug", GLOBAL_ARGS,
355355
usage="<topic>",
356356
description=(
357-
"Display information about the internals of coverage.py, "
358-
"for diagnosing problems. "
359-
"Topics are: "
360-
"'data' to show a summary of the collected data; "
361-
"'sys' to show installation information; "
362-
"'config' to show the configuration; "
357+
"Display information about the internals of coverage.py, " +
358+
"for diagnosing problems. " +
359+
"Topics are: " +
360+
"'data' to show a summary of the collected data; " +
361+
"'sys' to show installation information; " +
362+
"'config' to show the configuration; " +
363363
"'premain' to show what is calling coverage."
364364
),
365365
),
@@ -393,8 +393,8 @@ def get_prog_name(self):
393393
] + GLOBAL_ARGS,
394394
usage="[options] [modules]",
395395
description=(
396-
"Create an HTML report of the coverage of the files. "
397-
"Each file gets its own page, with the source decorated to show "
396+
"Create an HTML report of the coverage of the files. " +
397+
"Each file gets its own page, with the source decorated to show " +
398398
"executed, excluded, and missed lines."
399399
),
400400
),
@@ -732,9 +732,9 @@ def do_run(self, options, args):
732732
# they will be None if they have not been specified.
733733
if getattr(options, opt_name) is not None:
734734
show_help(
735-
"Options affecting multiprocessing must only be specified "
736-
"in a configuration file.\n"
737-
"Remove --{} from the command line.".format(opt_name)
735+
"Options affecting multiprocessing must only be specified " +
736+
"in a configuration file.\n" +
737+
f"Remove --{opt_name} from the command line."
738738
)
739739
return ERR
740740

coverage/execfile.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ def find_module(modulename):
5252
spec = importlib.util.find_spec(mod_main)
5353
if not spec:
5454
raise NoSource(
55-
"No module named %s; "
56-
"%r is a package and cannot be directly executed"
57-
% (mod_main, modulename)
55+
f"No module named {mod_main}; " +
56+
f"{modulename!r} is a package and cannot be directly executed"
5857
)
5958
pathname = spec.origin
6059
packagename = spec.name

coverage/parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def __init__(self, text, code=None, filename=None):
367367
for attr in ['co_lnotab', 'co_firstlineno']:
368368
if not hasattr(self.code, attr):
369369
raise StopEverything( # pragma: only jython
370-
"This implementation of Python doesn't support code analysis.\n"
370+
"This implementation of Python doesn't support code analysis.\n" +
371371
"Run coverage.py under another Python for this command."
372372
)
373373

tests/test_arcs.py

+21-23
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ def branches_3(l):
517517
branches_3([0,1])
518518
""",
519519
arcz=
520-
".1 18 8G GH H. "
521-
".2 23 34 43 26 3. 6. "
520+
".1 18 8G GH H. " +
521+
".2 23 34 43 26 3. 6. " +
522522
"-89 9A 9-8 AB BC CB B9 AE E9",
523523
arcz_missing="26 6."
524524
)
@@ -1077,18 +1077,18 @@ def check_token(data):
10771077
def test_except_jump_finally(self):
10781078
if env.PYBEHAVIOR.finally_jumps_back:
10791079
arcz = (
1080-
".1 1Q QR RS ST TU U. "
1081-
".2 23 34 45 56 4O 6L "
1082-
"78 89 9A AL LA AO 8B BC CD DL LD D4 BE EF FG GL LG G. EH HI IJ JL HL "
1083-
"L4 LM "
1080+
".1 1Q QR RS ST TU U. " +
1081+
".2 23 34 45 56 4O 6L " +
1082+
"78 89 9A AL LA AO 8B BC CD DL LD D4 BE EF FG GL LG G. EH HI IJ JL HL " +
1083+
"L4 LM " +
10841084
"MN NO O."
10851085
)
10861086
else:
10871087
arcz = (
1088-
".1 1Q QR RS ST TU U. "
1089-
".2 23 34 45 56 4O 6L "
1090-
"78 89 9A AL 8B BC CD DL BE EF FG GL EH HI IJ JL HL "
1091-
"LO L4 L. LM "
1088+
".1 1Q QR RS ST TU U. " +
1089+
".2 23 34 45 56 4O 6L " +
1090+
"78 89 9A AL 8B BC CD DL BE EF FG GL EH HI IJ JL HL " +
1091+
"LO L4 L. LM " +
10921092
"MN NO O."
10931093
)
10941094
self.check_coverage("""\
@@ -1131,18 +1131,18 @@ def func(x):
11311131
def test_else_jump_finally(self):
11321132
if env.PYBEHAVIOR.finally_jumps_back:
11331133
arcz = (
1134-
".1 1S ST TU UV VW W. "
1135-
".2 23 34 45 56 6A 78 8N 4Q "
1136-
"AB BC CN NC CQ AD DE EF FN NF F4 DG GH HI IN NI I. GJ JK KL LN JN "
1137-
"N4 NO "
1134+
".1 1S ST TU UV VW W. " +
1135+
".2 23 34 45 56 6A 78 8N 4Q " +
1136+
"AB BC CN NC CQ AD DE EF FN NF F4 DG GH HI IN NI I. GJ JK KL LN JN " +
1137+
"N4 NO " +
11381138
"OP PQ Q."
11391139
)
11401140
else:
11411141
arcz = (
1142-
".1 1S ST TU UV VW W. "
1143-
".2 23 34 45 56 6A 78 8N 4Q "
1144-
"AB BC CN AD DE EF FN DG GH HI IN GJ JK KL LN JN "
1145-
"N4 NQ N. NO "
1142+
".1 1S ST TU UV VW W. " +
1143+
".2 23 34 45 56 6A 78 8N 4Q " +
1144+
"AB BC CN AD DE EF FN DG GH HI IN GJ JK KL LN JN " +
1145+
"N4 NQ N. NO " +
11461146
"OP PQ Q."
11471147
)
11481148
self.check_coverage("""\
@@ -1280,9 +1280,7 @@ def double_inputs():
12801280
next(gen)
12811281
print(gen.send(6))
12821282
""",
1283-
arcz=
1284-
".1 17 78 89 9A AB B. "
1285-
".2 23 34 45 52 2.",
1283+
arcz=".1 17 78 89 9A AB B. .2 23 34 45 52 2.",
12861284
arcz_missing="2.",
12871285
)
12881286
assert self.stdout() == "20\n12\n"
@@ -1850,8 +1848,8 @@ async def print_sum(x, y): # 8
18501848
loop.close() # G
18511849
""",
18521850
arcz=
1853-
".1 13 38 8E EF FG G. "
1854-
"-34 45 56 6-3 "
1851+
".1 13 38 8E EF FG G. " +
1852+
"-34 45 56 6-3 " +
18551853
"-89 9C C-8",
18561854
arcz_unpredicted="5-3 9-8",
18571855
)

tests/test_concurrency.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,13 @@ def cant_trace_msg(concurrency, the_module):
187187
# We don't even have the underlying module installed, we expect
188188
# coverage to alert us to this fact.
189189
expected_out = (
190-
"Couldn't trace with concurrency=%s, "
191-
"the module isn't installed.\n" % concurrency
190+
f"Couldn't trace with concurrency={concurrency}, the module isn't installed.\n"
192191
)
193192
elif env.C_TRACER or concurrency == "thread" or concurrency == "":
194193
expected_out = None
195194
else:
196195
expected_out = (
197-
"Can't support concurrency=%s with PyTracer, "
198-
"only threads are supported\n" % concurrency
196+
f"Can't support concurrency={concurrency} with PyTracer, only threads are supported\n"
199197
)
200198
return expected_out
201199

tests/test_config.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ def test_parse_errors(self):
169169
("timid = 1\n", r"no section headers"),
170170
("[run\n", r"\[run"),
171171
("[report]\nexclude_lines = foo(\n",
172-
r"Invalid \[report\].exclude_lines value 'foo\(': "
172+
r"Invalid \[report\].exclude_lines value 'foo\(': " +
173173
r"(unbalanced parenthesis|missing \))"),
174174
("[report]\npartial_branches = foo[\n",
175-
r"Invalid \[report\].partial_branches value 'foo\[': "
175+
r"Invalid \[report\].partial_branches value 'foo\[': " +
176176
r"(unexpected end of regular expression|unterminated character set)"),
177177
("[report]\npartial_branches_always = foo***\n",
178-
r"Invalid \[report\].partial_branches_always value "
179-
r"'foo\*\*\*': "
178+
r"Invalid \[report\].partial_branches_always value " +
179+
r"'foo\*\*\*': " +
180180
r"multiple repeat"),
181181
]
182182

@@ -190,14 +190,14 @@ def test_parse_errors(self):
190190
("[tool.coverage.run]\ntimid = \"maybe?\"\n", r"maybe[?]"),
191191
("[tool.coverage.run\n", None),
192192
('[tool.coverage.report]\nexclude_lines = ["foo("]\n',
193-
r"Invalid \[tool.coverage.report\].exclude_lines value u?'foo\(': "
193+
r"Invalid \[tool.coverage.report\].exclude_lines value u?'foo\(': " +
194194
r"(unbalanced parenthesis|missing \))"),
195195
('[tool.coverage.report]\npartial_branches = ["foo["]\n',
196-
r"Invalid \[tool.coverage.report\].partial_branches value u?'foo\[': "
196+
r"Invalid \[tool.coverage.report\].partial_branches value u?'foo\[': " +
197197
r"(unexpected end of regular expression|unterminated character set)"),
198198
('[tool.coverage.report]\npartial_branches_always = ["foo***"]\n',
199-
r"Invalid \[tool.coverage.report\].partial_branches_always value "
200-
r"u?'foo\*\*\*': "
199+
r"Invalid \[tool.coverage.report\].partial_branches_always value " +
200+
r"u?'foo\*\*\*': " +
201201
r"multiple repeat"),
202202
('[tool.coverage.run]\nconcurrency="foo"', "not a list"),
203203
("[tool.coverage.report]\nprecision=1.23", "not an integer"),

tests/test_data.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ def test_debug_output_with_debug_option(self):
616616
self.assert_line_counts(covdata2, SUMMARY_1)
617617

618618
assert re.search(
619-
r"^Erasing data file '.*\.coverage'\n"
620-
r"Creating data file '.*\.coverage'\n"
619+
r"^Erasing data file '.*\.coverage'\n" +
620+
r"Creating data file '.*\.coverage'\n" +
621621
r"Opening data file '.*\.coverage'\n$",
622622
debug.get_output()
623623
)

tests/test_files.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def test_flat_rootname(original, flat):
9393

9494

9595
@pytest.mark.parametrize(
96-
"patterns, case_insensitive, partial,"
97-
"matches,"
96+
"patterns, case_insensitive, partial," +
97+
"matches," +
9898
"nomatches",
9999
[
100100
(

tests/test_numbits.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def setup_test(self):
115115

116116
def test_numbits_union(self):
117117
res = self.cursor.execute(
118-
"select numbits_union("
119-
"(select numbits from data where id = 7),"
120-
"(select numbits from data where id = 9)"
118+
"select numbits_union(" +
119+
"(select numbits from data where id = 7)," +
120+
"(select numbits from data where id = 9)" +
121121
")"
122122
)
123123
expected = [
@@ -129,9 +129,9 @@ def test_numbits_union(self):
129129

130130
def test_numbits_intersection(self):
131131
res = self.cursor.execute(
132-
"select numbits_intersection("
133-
"(select numbits from data where id = 7),"
134-
"(select numbits from data where id = 9)"
132+
"select numbits_intersection(" +
133+
"(select numbits from data where id = 7)," +
134+
"(select numbits from data where id = 9)" +
135135
")"
136136
)
137137
answer = numbits_to_nums(list(res)[0][0])

tests/test_oddball.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,9 @@ def test_unsets_trace():
484484

485485
out = self.stdout().replace(self.last_module_name, "coverage_test")
486486
expected = (
487-
"call: coverage_test.py @ 12\n"
488-
"line: coverage_test.py @ 13\n"
489-
"line: coverage_test.py @ 14\n"
487+
"call: coverage_test.py @ 12\n" +
488+
"line: coverage_test.py @ 13\n" +
489+
"line: coverage_test.py @ 14\n" +
490490
"return: coverage_test.py @ 14\n"
491491
)
492492
assert expected == out

tests/test_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def foo():
120120

121121
def test_indentation_error(self):
122122
msg = (
123-
"Couldn't parse '<code>' as Python source: "
123+
"Couldn't parse '<code>' as Python source: " +
124124
"'unindent does not match any outer indentation level' at line 3"
125125
)
126126
with pytest.raises(NotPython, match=msg):

0 commit comments

Comments
 (0)