Skip to content

Commit 013667f

Browse files
MAINT: Enforce ruff/flake8-comprehensions rules (C4) (#1498)
* MAINT: Apply ruff/flake8-comprehensions rule C401 C401 Unnecessary generator (rewrite as a set comprehension) * MAINT: Apply ruff/flake8-comprehensions rule C402 C402 Unnecessary generator (rewrite as a dict comprehension) * MAINT: Apply ruff/flake8-comprehensions rule C408 C408 Unnecessary `dict()` call (rewrite as a literal) * MAINT: Enforce ruff/flake8-comprehensions rules (C4)
1 parent 718d5a8 commit 013667f

12 files changed

+36
-35
lines changed

asv/commands/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def help(args):
8282
"help", help="Display usage information")
8383
help_parser.set_defaults(func=help)
8484

85-
commands = dict((x.__name__, x) for x in util.iter_subclasses(Command))
85+
commands = {x.__name__: x for x in util.iter_subclasses(Command)}
8686

8787
for command in command_order:
8888
subparser = commands[str(command)].setup_arguments(subparsers)

asv/commands/common_args.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ def add_global_arguments(parser, suppress_defaults=True):
1616
# parser should have suppress_defaults=False
1717

1818
if suppress_defaults:
19-
suppressor = dict(default=argparse.SUPPRESS)
19+
suppressor = {"default": argparse.SUPPRESS}
2020
else:
21-
suppressor = dict()
21+
suppressor = {}
2222

2323
parser.add_argument(
2424
"--verbose", "-v", action="store_true",

asv/commands/publish.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ def copy_ignore(src, names):
157157
tags[tag] = revisions[tags[tag]]
158158
hash_to_date[commit_hash] = repo.get_date_from_name(commit_hash)
159159

160-
revision_to_date = dict((r, hash_to_date[h]) for h, r in revisions.items())
160+
revision_to_date = {r: hash_to_date[h] for h, r in revisions.items()}
161161

162-
branches = dict(
163-
(branch, repo.get_branch_commits(branch))
164-
for branch in conf.branches)
162+
branches = {
163+
branch: repo.get_branch_commits(branch)
164+
for branch in conf.branches}
165165

166166
log.step()
167167
log.info("Loading results")
@@ -266,7 +266,7 @@ def copy_ignore(src, names):
266266
val.sort(key=lambda x: '[none]' if x is None else str(x))
267267
params[key] = val
268268
params['branch'] = [repo.get_branch_name(branch) for branch in conf.branches]
269-
revision_to_hash = dict((r, h) for h, r in revisions.items())
269+
revision_to_hash = {r: h for h, r in revisions.items()}
270270
util.write_json(os.path.join(conf.html_dir, "index.json"), {
271271
'project': conf.project,
272272
'project_url': conf.project_url,

asv/environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ def _interpolate_commands(self, commands):
798798

799799
# All environment variables are available as interpolation variables,
800800
# lowercased without the prefix.
801-
kwargs = dict()
801+
kwargs = {}
802802
for key, value in self._global_env_vars.items():
803803
if key == 'ASV':
804804
continue

asv/plugins/regressions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def publish(cls, conf, repo, benchmarks, graphs, revisions):
2424
# it's easier to work with than the results directly
2525

2626
regressions = []
27-
revision_to_hash = dict((r, h) for h, r in revisions.items())
27+
revision_to_hash = {r: h for h, r in revisions.items()}
2828

2929
data_filter = _GraphDataFilter(conf, repo, revisions)
3030

asv/plugins/summarylist.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ def publish(cls, conf, repo, benchmarks, graphs, revisions):
8989
# Revision range (left-exclusive)
9090
change_rev = [prev_piece[1] - 1, last_piece[0]]
9191

92-
row = dict(name=benchmark_name,
93-
idx=idx,
94-
pretty_name=pretty_name,
95-
last_rev=last_rev,
96-
last_value=last_value,
97-
last_err=last_err,
98-
prev_value=prev_value,
99-
change_rev=change_rev)
92+
row = {'name': benchmark_name,
93+
'idx': idx,
94+
'pretty_name': pretty_name,
95+
'last_rev': last_rev,
96+
'last_value': last_value,
97+
'last_err': last_err,
98+
'prev_value': prev_value,
99+
'change_rev': change_rev}
100100

101101
# Generate summary data filename.
102102
# Note that 'summary' is not a valid benchmark name, so that we can

asv/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ def get_content(header=None):
396396

397397
log.debug(f"Running '{' '.join(args)}'")
398398

399-
kwargs = dict(shell=shell, env=env, cwd=cwd,
400-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
399+
kwargs = {'shell': shell, 'env': env, 'cwd': cwd,
400+
'stdout': subprocess.PIPE, 'stderr': subprocess.PIPE}
401401
if redirect_stderr:
402402
kwargs['stderr'] = subprocess.STDOUT
403403
if WIN:
@@ -1179,7 +1179,7 @@ def interpolate_command(command, variables):
11791179
m = re.match('^return-code=([0-9,]+)$', result[0])
11801180
if m:
11811181
try:
1182-
return_codes = set(int(x) for x in m.group(1).split(","))
1182+
return_codes = {int(x) for x in m.group(1).split(",")}
11831183
return_codes_set = True
11841184
del result[0]
11851185
continue

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ extend-exclude = [
120120

121121
[tool.ruff.lint]
122122
extend-select = [
123+
"C4",
123124
"I",
124125
]
125126
ignore = [

test/test_environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ def test_environment_env_matrix():
906906
environments = list(environment.get_environments(conf, None))
907907

908908
assert len(environments) == environ_count
909-
assert len(set(e.dir_name for e in environments)) == build_count
909+
assert len({e.dir_name for e in environments}) == build_count
910910

911911

912912
def test__parse_matrix():

test/test_publish.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def test_publish(tmpdir, example_results):
9191
assert index['params']['branch'] == [f'{util.git_default_branch()}']
9292

9393
repo = get_repo(conf)
94-
revision_to_hash = dict((r, h) for h, r in repo.get_revisions(commits).items())
94+
revision_to_hash = {r: h for h, r in repo.get_revisions(commits).items()}
9595

9696
def check_file(branch, cython):
9797
fn = join(tmpdir, 'html', 'graphs', cython, 'arch-x86_64', 'branch-' + branch,
@@ -284,10 +284,10 @@ def test_regression_multiple_branches(dvcs_type, tmpdir):
284284
],
285285
)
286286
commit_values = {}
287-
branches = dict(
288-
(branch, list(reversed(dvcs.get_branch_hashes(branch))))
287+
branches = {
288+
branch: list(reversed(dvcs.get_branch_hashes(branch)))
289289
for branch in (main, "stable")
290-
)
290+
}
291291
for branch, values in (
292292
(main, 10 * [1]),
293293
("stable", 5 * [1] + 5 * [2]),

test/test_results.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def _truncate_floats(item, digits=5):
1717
elif isinstance(item, list):
1818
return [_truncate_floats(x, digits) for x in item]
1919
elif isinstance(item, dict):
20-
return dict((k, _truncate_floats(v)) for k, v in item.items())
20+
return {k: _truncate_floats(v) for k, v in item.items()}
2121
else:
2222
return item
2323

test/test_util.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,28 +300,28 @@ def test_json_non_ascii(tmpdir):
300300

301301
def test_interpolate_command():
302302
good_items = [
303-
('python {inputs}', dict(inputs='9'),
303+
('python {inputs}', {'inputs': '9'},
304304
['python', '9'], {}, {0}, None),
305305

306-
('python "{inputs}"', dict(inputs='9'),
306+
('python "{inputs}"', {'inputs': '9'},
307307
['python', '9'], {}, {0}, None),
308308

309-
('python {inputs}', dict(inputs=''),
309+
('python {inputs}', {'inputs': ''},
310310
['python', ''], {}, {0}, None),
311311

312-
('HELLO="asd" python "{inputs}"', dict(inputs='9'),
312+
('HELLO="asd" python "{inputs}"', {'inputs': '9'},
313313
['python', '9'], {'HELLO': 'asd'}, {0}, None),
314314

315-
('HELLO="asd" return-code=any python "{inputs}"', dict(inputs='9'),
315+
('HELLO="asd" return-code=any python "{inputs}"', {'inputs': '9'},
316316
['python', '9'], {'HELLO': 'asd'}, None, None),
317317

318-
('HELLO="asd" return-code=255 python "{inputs}"', dict(inputs='9'),
318+
('HELLO="asd" return-code=255 python "{inputs}"', {'inputs': '9'},
319319
['python', '9'], {'HELLO': 'asd'}, {255}, None),
320320

321-
('HELLO="asd" return-code=255 python "{inputs}"', dict(inputs='9'),
321+
('HELLO="asd" return-code=255 python "{inputs}"', {'inputs': '9'},
322322
['python', '9'], {'HELLO': 'asd'}, {255}, None),
323323

324-
('HELLO="asd" in-dir="{somedir}" python', dict(somedir='dir'),
324+
('HELLO="asd" in-dir="{somedir}" python', {'somedir': 'dir'},
325325
['python'], {'HELLO': 'asd'}, {0}, 'dir'),
326326
]
327327

0 commit comments

Comments
 (0)