Skip to content

chore: trivial idiom cleanups (ruff PIE810, FURB167, B009)#135

Open
alexzhu0 wants to merge 1 commit intoFlowElement-ai:mainfrom
alexzhu0:chore/trivial-idiom-pie810-furb167-b009
Open

chore: trivial idiom cleanups (ruff PIE810, FURB167, B009)#135
alexzhu0 wants to merge 1 commit intoFlowElement-ai:mainfrom
alexzhu0:chore/trivial-idiom-pie810-furb167-b009

Conversation

@alexzhu0
Copy link
Copy Markdown
Contributor

@alexzhu0 alexzhu0 commented May 1, 2026

Summary

Three ruff-autofix rule groups bundled together. All 15 changes are semantics-preserving Python idiom cleanups.

Changes

Rule Count Before → After
PIE810 5 x.startswith("a") or x.startswith("b")x.startswith(("a", "b"))
FURB167 5 re.I, re.Mre.IGNORECASE, re.MULTILINE
B009 5 getattr(obj, "id")obj.id

PIE810 sites

  • api/v1/prompts/routers/get_prompts_router.py (3×)
  • memory/episodic/routing/document_router.py
  • shared/files/utils/get_data_file_path.py

str.startswith accepts a tuple of prefixes natively; one call instead of two.

FURB167 sites

  • knowledge/summarization/summarize_by_event.py
  • knowledge/summarization/text_summary_parser.py (3×)
  • memory/procedural/procedural_points_builder.py

The full names (re.IGNORECASE, re.MULTILINE) are the canonical form in Python's re docs; single-letter aliases are easy to misread.

B009 sites

  • retrieval/episodic/bundle_search.py (3×)
  • retrieval/utils/fine_grained_triplet_search.py
  • retrieval/utils/procedural_bundle_search.py

getattr(obj, "id") with a constant attribute offers no safety over obj.id, and hides typos from IDE tooling / static analysis.

Verification

$ ruff check <touched files> --select B009,FURB167,PIE810
All checks passed!

$ python -m py_compile <touched files>   # clean

I affirm that all code in every commit of this pull request conforms to the terms of the M-flow Developer Certificate of Origin

@FlowElement-ai
Copy link
Copy Markdown
Owner

Thanks for this cleanup! Two small things hold this back from merging:

  1. DCO: I added the affirmation to the PR body for you, the Verify DCO statement check should pass now.
  2. Fork PR lightweight checks still fails because m_flow/ingestion/documents/classify_documents.py (the file your dict.fromkeys autofix touches) is unformatted under the repo-pinned ruff 0.13.1 in uv.lock. Newer ruff joins the 16-element image-extension list into one line (>120 chars), but 0.13.1 wants the list re-expanded.

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-lease

Same 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!

FlowElement-ai added a commit that referenced this pull request May 1, 2026
#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>
FlowElement-ai added a commit that referenced this pull request May 1, 2026
…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>
@FlowElement-ai
Copy link
Copy Markdown
Owner

Quick update: I just merged #142 which bumps the lockfile ruff from 0.13.1 → 0.15.10 to match the pyproject.toml ceiling. That was the version that disagreed with your autofix output on every recent fork PR.

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-lease

After 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.

Three bundled ruff-autofix rules, all semantics-preserving.

PIE810 × 5 — x.startswith("a") or x.startswith("b") → x.startswith(("a", "b"))
  startswith accepts a tuple of prefixes natively; one call, one match
  pass, clearer intent.
  - m_flow/api/v1/prompts/routers/get_prompts_router.py (3x)
  - m_flow/memory/episodic/routing/document_router.py (1x)
  - m_flow/shared/files/utils/get_data_file_path.py (1x)

FURB167 × 5 — re.I/re.M → re.IGNORECASE/re.MULTILINE
  Full names are the canonical form in the re docs. Single-letter
  aliases are easy to misread at a glance.
  - m_flow/knowledge/summarization/summarize_by_event.py
  - m_flow/knowledge/summarization/text_summary_parser.py (3x)
  - m_flow/memory/procedural/procedural_points_builder.py

B009 × 5 — getattr(obj, "id") → obj.id
  getattr with a constant attribute name offers no safety vs. direct
  access but hides typos from tooling / static analysis.
  - m_flow/retrieval/episodic/bundle_search.py (3x)
  - m_flow/retrieval/utils/fine_grained_triplet_search.py
  - m_flow/retrieval/utils/procedural_bundle_search.py

Verification:
  ruff check --select B009,FURB167,PIE810 on touched files: clean
  py_compile on all touched files: clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants