Skip to content

Enable more ruff rules - #7470

Open
danielhollas wants to merge 3 commits into
aiidateam:mainfrom
danielhollas:enable-more-ruff
Open

Enable more ruff rules#7470
danielhollas wants to merge 3 commits into
aiidateam:mainfrom
danielhollas:enable-more-ruff

Conversation

@danielhollas

Copy link
Copy Markdown
Collaborator

This is a follow-up to the recent ruff upgrades, where I purposefully disabled some rules that had a lot of hits to ease review.

Here I enable three more rules and fix (or add noqas) all the hits

RUFF043

What it does

Checks for non-raw literal string arguments passed to the match parameter
of pytest.raises() where the string contains at least one unescaped
regex metacharacter.

Why is this bad?

The match argument is implicitly converted to a regex under the hood.
It should be made explicit whether the string is meant to be a regex or a "plain" pattern
by prefixing the string with the r suffix, escaping the metacharacter(s)
in the string using backslashes, or wrapping the entire string in a call to
re.escape().

RUF059 (unused-unpacked-variable)

What it does

Checks for the presence of unused variables in unpacked assignments.

Why is this bad?

A variable that is defined but never used can confuse readers.

If a variable is intentionally defined-but-not-used, it should be
prefixed with an underscore, or some other value that adheres to the
[lint.dummy-variable-rgx] pattern.

PLR0911 (too-many-return-statements)

What it does

Checks for functions or methods with too many return statements.
By default, this rule allows up to six return statements, as configured by
the [lint.pylint.max-returns] option.

Why is this bad?

Functions or methods with many return statements are harder to understand
and maintain, and often indicative of complex logic.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.62%. Comparing base (45e53ed) to head (60dc191).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7470   +/-   ##
=======================================
  Coverage   80.62%   80.62%           
=======================================
  Files         580      580           
  Lines       46754    46754           
=======================================
  Hits        37691    37691           
  Misses       9063     9063           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fd775b93-d721-4078-8563-5e8abe4a34a0

📥 Commits

Reviewing files that changed from the base of the PR and between e0b8433 and 60dc191.

📒 Files selected for processing (15)
  • tests/engine/daemon/test_client.py
  • tests/engine/processes/test_control.py
  • tests/engine/test_runners.py
  • tests/engine/test_work_chain.py
  • tests/orm/data/code/test_abstract.py
  • tests/orm/data/code/test_containerized.py
  • tests/orm/data/code/test_installed.py
  • tests/orm/data/code/test_portable.py
  • tests/orm/nodes/data/test_array.py
  • tests/orm/nodes/data/test_jsonable.py
  • tests/orm/nodes/data/test_trajectory.py
  • tests/schedulers/test_slurm.py
  • tests/test_conftest.py
  • tests/tools/archive/migration/test_v06_to_v07.py
  • tests/transports/test_all_plugins.py
🚧 Files skipped from review as they are similar to previous changes (10)
  • tests/orm/data/code/test_portable.py
  • tests/tools/archive/migration/test_v06_to_v07.py
  • tests/orm/nodes/data/test_jsonable.py
  • tests/orm/nodes/data/test_trajectory.py
  • tests/orm/data/code/test_abstract.py
  • tests/orm/data/code/test_installed.py
  • tests/engine/test_work_chain.py
  • tests/test_conftest.py
  • tests/transports/test_all_plugins.py
  • tests/schedulers/test_slurm.py

📝 Walkthrough

Walkthrough

This PR narrows Ruff ignores, adds targeted PLR0911 suppressions, marks unused values explicitly, and corrects pytest regex literals and expected message patterns. Runtime behavior is otherwise unchanged.

Changes

Lint cleanup and warning compliance

Layer / File(s) Summary
Ruff configuration and suppressions
pyproject.toml, src/aiida/..., .molecule/..., tests/orm/...
Removed selected global Ruff ignores and added targeted PLR0911 suppressions.
Runtime unused-value cleanup
src/aiida/restapi/resources.py, src/aiida/transports/plugins/async_backend.py
Renamed unused parsed values and command outputs with underscore-prefixed names.
Test fixture and return-value cleanup
tests/cmdline/..., tests/conftest.py, tests/engine/test_run.py
Updated tuple unpacking and return-value assignments to discard unused values explicitly.
Raw regex assertion updates
tests/**
Converted exception-message patterns to raw strings and aligned escaped punctuation and trailing message text.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: agoscinski, geigerj2

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 67.12% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: enabling additional Ruff rules and fixing related violations.
Description check ✅ Passed The description accurately describes the Ruff rule changes and associated fixes/noqa updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/schedulers/test_slurm.py`:
- Around line 59-61: Update the ValueError match pattern in the SlurmJobResource
test to use a single escaped asterisk in the raw regex, so it matches the
literal “*” in the error message rather than backslashes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5be77c4f-4616-4935-a97b-bd1e076c56ad

📥 Commits

Reviewing files that changed from the base of the PR and between 45e53ed and e0b8433.

📒 Files selected for processing (35)
  • .molecule/default/files/polish/lib/expression.py
  • pyproject.toml
  • src/aiida/engine/processes/calcjobs/calcjob.py
  • src/aiida/engine/processes/workchains/restart.py
  • src/aiida/orm/nodes/data/array/bands.py
  • src/aiida/orm/utils/node.py
  • src/aiida/restapi/resources.py
  • src/aiida/storage/sqlite_zip/orm.py
  • src/aiida/tools/dbimporters/plugins/icsd.py
  • src/aiida/transports/plugins/async_backend.py
  • tests/cmdline/params/types/test_calculation.py
  • tests/cmdline/params/types/test_code.py
  • tests/cmdline/params/types/test_group.py
  • tests/cmdline/utils/test_common.py
  • tests/conftest.py
  • tests/engine/daemon/test_client.py
  • tests/engine/processes/test_control.py
  • tests/engine/test_run.py
  • tests/engine/test_runners.py
  • tests/engine/test_work_chain.py
  • tests/manage/configuration/test_config.py
  • tests/orm/data/code/test_abstract.py
  • tests/orm/data/code/test_containerized.py
  • tests/orm/data/code/test_installed.py
  • tests/orm/data/code/test_portable.py
  • tests/orm/models/test_models.py
  • tests/orm/nodes/data/test_array.py
  • tests/orm/nodes/data/test_data.py
  • tests/orm/nodes/data/test_jsonable.py
  • tests/orm/nodes/data/test_remote.py
  • tests/orm/nodes/data/test_trajectory.py
  • tests/schedulers/test_slurm.py
  • tests/test_conftest.py
  • tests/tools/archive/migration/test_v06_to_v07.py
  • tests/transports/test_all_plugins.py

Comment thread tests/schedulers/test_slurm.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants