Skip to content

chore: drop redundant "r" mode argument to open() (ruff UP015)#164

Open
alexzhu0 wants to merge 1 commit intoFlowElement-ai:mainfrom
alexzhu0:chore/ruff-up015-drop-redundant-open-modes
Open

chore: drop redundant "r" mode argument to open() (ruff UP015)#164
alexzhu0 wants to merge 1 commit intoFlowElement-ai:mainfrom
alexzhu0:chore/ruff-up015-drop-redundant-open-modes

Conversation

@alexzhu0
Copy link
Copy Markdown
Contributor

@alexzhu0 alexzhu0 commented May 3, 2026

Summary

Ruff rule UP015 flags open(path, "r", ...) where the mode argument is redundant — Python's open() defaults to mode="r" (text-read) when the argument is omitted, so dropping the literal "r" is byte-identical. 9 occurrences, all auto-fixable.

-        with open(self.dataset_path, "r", encoding="utf-8") as f:
+        with open(self.dataset_path, encoding="utf-8") as f:
             for line_num, line in enumerate(f, 1):

Semantic equivalence

Python's open() docs state that mode defaults to "r":

The default mode is 'r' (open for reading text, a synonym of 'rt').

Removing the explicit "r" leaves text-read mode unchanged. No positional/keyword argument shift either — encoding is already keyword-only in every touched site.

Scope

9 files, 9 sites, +9 / −9 (pure argument removal).

File Sites
examples/episodic_stage5_smoke_test.py 1
m_flow/debug/trace_cli.py 1
m_flow/eval/config.py 1
m_flow/eval/loader.py 1
m_flow/eval/report.py 1
m_flow/llm/prompts/read_query_prompt.py 1
m_flow/shared/loaders/core/csv_loader.py 1
m_flow/shared/loaders/core/text_loader.py 1
m_flow/tests/tasks/descriptive_metrics/metrics_test_utils.py 1

Verification

$ uv run ruff check . --exclude 'm_flow/baml_client' --exclude 'm_flow-frontend' --select UP015
All checks passed!

$ for f in $(git diff --name-only main); do uv run python -c "import ast; ast.parse(open('$f').read())"; done
# clean across all 9 files

No behavior change. Generated code under m_flow/baml_client/ is untouched.

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

Ruff rule UP015 flags `open(path, "r", ...)` where the `"r"` mode is the
default and thus redundant. Removing it is purely cosmetic — Python `open()`
defaults to text-read mode when `mode` is omitted, so the behavior is
byte-identical.

Verification:
- `uv run ruff check ... --select UP015` is now clean
- ast.parse on every touched file: clean

No behavior change.
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.

1 participant