Skip to content

Enable ruff I (import sorting) rule#1348

Merged
bdraco merged 2 commits into
aio-libs:masterfrom
bdraco:ruff-add-isort-rule
May 17, 2026
Merged

Enable ruff I (import sorting) rule#1348
bdraco merged 2 commits into
aio-libs:masterfrom
bdraco:ruff-add-isort-rule

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented May 17, 2026

What do these changes do?

Enables the I (import sorting) rule in [tool.ruff.lint]
alongside the existing UP (pyupgrade) group, and updates the
ruff-check pre-commit hook to run with
--fix --exit-non-zero-on-fix --show-fixes so import-order fixes
apply on commit (and abort the commit when something changed). This
follows the same pattern as yarl PR
#1698: one tool, one
rev, for both formatting and import sorting.

Sorted imports in six files where ruff check --select I --fix
found drift (tests/conftest.py,
tests/isolated/multidict_pop.py,
tests/test_circular_imports.py,
tests/test_mutable_multidict.py,
benchmarks/benchmark.py, benchmarks/istr.py).

AGENTS.md updated to reflect the additional lint group, so the
"only the UP group enabled" guidance no longer contradicts the
config.

Are there changes in behavior for the user?

No, contributor tooling only.

Is it a substantial burden for the maintainers to support this?

No. One additional lint rule sharing the existing [tool.ruff]
config; no new pre-commit hooks were added.

Related issue number

N/A; mirrors the approach taken in yarl #1698.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist: N/A (tooling-only change; ran the touched test modules and the full pre-commit suite to verify)
  • Documentation reflects the changes: N/A (no user-visible API change; AGENTS.md updated)
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt: N/A (no such file in this repo)
  • Add a new news fragment into the CHANGES/ folder (CHANGES/1348.contrib.rst)
Agent run details (optional, for reviewers)

Drafted with Claude Code (Opus 4.7); reviewed by @bdraco.

Verified:

$ ruff check multidict/ tests/ benchmarks/
All checks passed!
$ ruff format --check multidict/ tests/
29 files already formatted
$ python3 -m pytest tests/test_circular_imports.py tests/test_mutable_multidict.py --no-cov -q -W ignore::UserWarning
137 passed in 0.30s
$ pre-commit run --all-files
all hooks passed (including mypy py311 + py313)
$ make doc-spelling
5 pre-existing CHANGES.rst misspellings only; CHANGES/1348.contrib.rst is clean

Adds ``I`` to ``[tool.ruff.lint]`` select alongside ``UP``, so ruff
also covers import order. The ``ruff-check`` pre-commit hook now runs
with ``--fix --exit-non-zero-on-fix --show-fixes`` so import-order
fixes apply on commit and abort the commit when something changed.
Sorted imports in six files to match the new rule. AGENTS.md updated
to mention the additional lint group.
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label May 17, 2026
@bdraco bdraco marked this pull request as ready for review May 17, 2026 18:09
@bdraco bdraco requested review from asvetlov and webknjaz as code owners May 17, 2026 18:09
@bdraco bdraco enabled auto-merge (squash) May 17, 2026 18:10
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 17, 2026

Merging this PR will not alter performance

✅ 244 untouched benchmarks


Comparing bdraco:ruff-add-isort-rule (dfff2af) with master (fc6933d)

Open in CodSpeed

The CHANGES/1348.contrib.rst fragment references ruff's pyupgrade
group; without this entry the towncrier-fragments preview that the
docs build inlines into changes.rst fails the spell check.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.86%. Comparing base (fc6933d) to head (dfff2af).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1348   +/-   ##
=======================================
  Coverage   99.86%   99.86%           
=======================================
  Files          28       28           
  Lines        3627     3627           
  Branches      265      265           
=======================================
  Hits         3622     3622           
  Misses          3        3           
  Partials        2        2           
Flag Coverage Δ
CI-GHA 99.86% <100.00%> (ø)
pytest 99.86% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@bdraco bdraco merged commit 1b67154 into aio-libs:master May 17, 2026
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant