Skip to content

MAINT: Enforce ruff/flake8-comprehensions rules (C4) #1498

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

Merged
merged 4 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion asv/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def help(args):
"help", help="Display usage information")
help_parser.set_defaults(func=help)

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

for command in command_order:
subparser = commands[str(command)].setup_arguments(subparsers)
Expand Down
4 changes: 2 additions & 2 deletions asv/commands/common_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def add_global_arguments(parser, suppress_defaults=True):
# parser should have suppress_defaults=False

if suppress_defaults:
suppressor = dict(default=argparse.SUPPRESS)
suppressor = {"default": argparse.SUPPRESS}
else:
suppressor = dict()
suppressor = {}

parser.add_argument(
"--verbose", "-v", action="store_true",
Expand Down
10 changes: 5 additions & 5 deletions asv/commands/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ def copy_ignore(src, names):
tags[tag] = revisions[tags[tag]]
hash_to_date[commit_hash] = repo.get_date_from_name(commit_hash)

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

branches = dict(
(branch, repo.get_branch_commits(branch))
for branch in conf.branches)
branches = {
branch: repo.get_branch_commits(branch)
for branch in conf.branches}

log.step()
log.info("Loading results")
Expand Down Expand Up @@ -266,7 +266,7 @@ def copy_ignore(src, names):
val.sort(key=lambda x: '[none]' if x is None else str(x))
params[key] = val
params['branch'] = [repo.get_branch_name(branch) for branch in conf.branches]
revision_to_hash = dict((r, h) for h, r in revisions.items())
revision_to_hash = {r: h for h, r in revisions.items()}
util.write_json(os.path.join(conf.html_dir, "index.json"), {
'project': conf.project,
'project_url': conf.project_url,
Expand Down
2 changes: 1 addition & 1 deletion asv/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def _interpolate_commands(self, commands):

# All environment variables are available as interpolation variables,
# lowercased without the prefix.
kwargs = dict()
kwargs = {}
for key, value in self._global_env_vars.items():
if key == 'ASV':
continue
Expand Down
2 changes: 1 addition & 1 deletion asv/plugins/regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def publish(cls, conf, repo, benchmarks, graphs, revisions):
# it's easier to work with than the results directly

regressions = []
revision_to_hash = dict((r, h) for h, r in revisions.items())
revision_to_hash = {r: h for h, r in revisions.items()}

data_filter = _GraphDataFilter(conf, repo, revisions)

Expand Down
16 changes: 8 additions & 8 deletions asv/plugins/summarylist.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ def publish(cls, conf, repo, benchmarks, graphs, revisions):
# Revision range (left-exclusive)
change_rev = [prev_piece[1] - 1, last_piece[0]]

row = dict(name=benchmark_name,
idx=idx,
pretty_name=pretty_name,
last_rev=last_rev,
last_value=last_value,
last_err=last_err,
prev_value=prev_value,
change_rev=change_rev)
row = {'name': benchmark_name,
'idx': idx,
'pretty_name': pretty_name,
'last_rev': last_rev,
'last_value': last_value,
'last_err': last_err,
'prev_value': prev_value,
'change_rev': change_rev}

# Generate summary data filename.
# Note that 'summary' is not a valid benchmark name, so that we can
Expand Down
6 changes: 3 additions & 3 deletions asv/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ def get_content(header=None):

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

kwargs = dict(shell=shell, env=env, cwd=cwd,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
kwargs = {'shell': shell, 'env': env, 'cwd': cwd,
'stdout': subprocess.PIPE, 'stderr': subprocess.PIPE}
if redirect_stderr:
kwargs['stderr'] = subprocess.STDOUT
if WIN:
Expand Down Expand Up @@ -1179,7 +1179,7 @@ def interpolate_command(command, variables):
m = re.match('^return-code=([0-9,]+)$', result[0])
if m:
try:
return_codes = set(int(x) for x in m.group(1).split(","))
return_codes = {int(x) for x in m.group(1).split(",")}
return_codes_set = True
del result[0]
continue
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ extend-exclude = [

[tool.ruff.lint]
extend-select = [
"C4",
"I",
]
ignore = [
Expand Down
2 changes: 1 addition & 1 deletion test/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ def test_environment_env_matrix():
environments = list(environment.get_environments(conf, None))

assert len(environments) == environ_count
assert len(set(e.dir_name for e in environments)) == build_count
assert len({e.dir_name for e in environments}) == build_count


def test__parse_matrix():
Expand Down
8 changes: 4 additions & 4 deletions test/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_publish(tmpdir, example_results):
assert index['params']['branch'] == [f'{util.git_default_branch()}']

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

def check_file(branch, cython):
fn = join(tmpdir, 'html', 'graphs', cython, 'arch-x86_64', 'branch-' + branch,
Expand Down Expand Up @@ -284,10 +284,10 @@ def test_regression_multiple_branches(dvcs_type, tmpdir):
],
)
commit_values = {}
branches = dict(
(branch, list(reversed(dvcs.get_branch_hashes(branch))))
branches = {
branch: list(reversed(dvcs.get_branch_hashes(branch)))
for branch in (main, "stable")
)
}
for branch, values in (
(main, 10 * [1]),
("stable", 5 * [1] + 5 * [2]),
Expand Down
2 changes: 1 addition & 1 deletion test/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _truncate_floats(item, digits=5):
elif isinstance(item, list):
return [_truncate_floats(x, digits) for x in item]
elif isinstance(item, dict):
return dict((k, _truncate_floats(v)) for k, v in item.items())
return {k: _truncate_floats(v) for k, v in item.items()}
else:
return item

Expand Down
16 changes: 8 additions & 8 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,28 +300,28 @@ def test_json_non_ascii(tmpdir):

def test_interpolate_command():
good_items = [
('python {inputs}', dict(inputs='9'),
('python {inputs}', {'inputs': '9'},
['python', '9'], {}, {0}, None),

('python "{inputs}"', dict(inputs='9'),
('python "{inputs}"', {'inputs': '9'},
['python', '9'], {}, {0}, None),

('python {inputs}', dict(inputs=''),
('python {inputs}', {'inputs': ''},
['python', ''], {}, {0}, None),

('HELLO="asd" python "{inputs}"', dict(inputs='9'),
('HELLO="asd" python "{inputs}"', {'inputs': '9'},
['python', '9'], {'HELLO': 'asd'}, {0}, None),

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

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

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

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

Expand Down
Loading