chore: simplify redundant dict comprehensions (ruff C416, C420)#131
chore: simplify redundant dict comprehensions (ruff C416, C420)#131alexzhu0 wants to merge 1 commit intoFlowElement-ai:mainfrom
Conversation
|
Thanks for this cleanup! Two small things hold this back from merging:
To unblock, please run locally and push: uv sync --group dev
uv run ruff format m_flow/ingestion/documents/classify_documents.py
git commit --amend --no-edit && git push --force-with-leaseSame idea applies to your other open PRs that 're hitting the same fork-lite check. After that the queue should go green and we can merge the batch. Thanks! |
#137) The repo's `uv.lock` pins `ruff==0.13.1` and the fork-lite CI job runs `uv run ruff format --check .` against the whole tree. After PR #131 (``dict.fromkeys`` autofix) was merged via a different ruff version, the 16-element ``_IMAGE_EXTS`` list ended up on a single line that exceeds the project's 120-char limit. ruff 0.13.1 wants the list re-expanded; the resulting drift was silently breaking every subsequent fork PR's ``Fork PR lightweight checks`` step (observed on PRs #131, #134, #135). Re-run ``ruff==0.13.1 format`` on the file. Tree is now ``1061 files already formatted`` under the locked ruff version. Co-authored-by: Junting Hua <juntinghua@Juntings-MacBook-Pro.local>
…t upper bound (#142) `pyproject.toml` declared `ruff>=0.9.0,<=0.15.10` but `uv.lock` was still pinned at 0.13.1, releases behind. Contributors who installed ruff manually (or whose editor picked up a newer ruff) ran format autofixes that 0.13.1 would refuse, producing CI noise on every fork PR even when the code was logically correct. This was the direct root cause of: - PR #137 (the one-off `classify_documents.py` reformat I had to land) - The persistent `Fork PR lightweight checks` failures on PR #131, #134, and #135 — all caused by `ruff==0.13.1` reformatting files the contributors' newer ruff considered correct - Several earlier rounds of "fork-lite is red even though the diff looks fine" debugging `uv lock --upgrade-package ruff` snaps the lock file to the constraint ceiling (0.15.10). Verification on main: - `ruff==0.15.10 format --check .` → 1061 files already formatted - `ruff==0.15.10 check .` → all checks passed So the upgrade introduces zero source code change and aligns the CI ruff with what contributors and their editors are running. Co-authored-by: Junting Hua <juntinghua@Juntings-MacBook-Pro.local>
|
Quick update: I just merged #142 which bumps the lockfile ruff from 0.13.1 → 0.15.10 to match the Triggered a fork-lite rerun on this PR with the new lock — it still failed, which means your ruff is even newer than 0.15.10. The smallest unblock is one of: # either downgrade locally to match the repo
uv tool install ruff@0.15.10
ruff format .
# or just re-run with whatever ruff comes from the project venv
uv run ruff format .
git add -u && git commit --amend --no-edit && git push --force-with-leaseAfter that the fork-lite check should go green and we can merge. Sorry for the back and forth on this one — the lockfile drift was the underlying cause. |
Replace `{k: v for k in iter}` with `dict.fromkeys(iter, v)` (C420, 4x)
and `{k: v for k, v in zip(a, b)}` with `dict(zip(a, b))` (C416, 4x).
These are pure idiom cleanups flagged by ruff's flake8-comprehensions
rules. `dict.fromkeys` and `dict()` are marginally faster and more
readable, with identical behavior. Verified: same keys, same values,
same order.
Files touched:
- m_flow/eval/report.py
- m_flow/ingestion/documents/classify_documents.py
- m_flow/retrieval/episodic/bundle_search.py
- m_flow/retrieval/utils/fine_grained_triplet_search.py
- m_flow/retrieval/utils/procedural_bundle_search.py
- m_flow/tests/test_relational_db_migration.py
2e596d0 to
6607785
Compare
Summary
Two small ruff-flagged idiom cleanups from the
flake8-comprehensionsfamily:{k: v for k in it}→dict.fromkeys(it, v)(4 sites){k: v for k, v in zip(a, b)}→dict(zip(a, b))(4 sites)Same behavior, slightly faster, and more obvious intent at a glance. After this PR,
ruff check --select C416,C420 m_flow/is clean.Files
m_flow/eval/report.pyFAILURE_BUCKETSzero-initm_flow/ingestion/documents/classify_documents.pym_flow/retrieval/episodic/bundle_search.pym_flow/retrieval/utils/fine_grained_triplet_search.pym_flow/retrieval/utils/procedural_bundle_search.pym_flow/tests/test_relational_db_migration.pyVerification
No behavior change. No new tests needed — these rules flag exact semantic equivalents.
I affirm that all code in every commit of this pull request conforms to the terms of the M-flow Developer Certificate of Origin