Skip to content

Commit fa3d023

Browse files
smackeseyDagster Devtools
authored andcommitted
ruff: enable PLW1514 (unspecified-encoding) and fix violations (#25376)
## Summary & Motivation Enables Ruff's [PLW1514 (`unspecified-encoding`)](https://docs.astral.sh/ruff/rules/unspecified-encoding/) and fixes the 576 violations it surfaced. `open()`, `Path.read_text()`, and `Path.write_text()` calls in text mode default to the platform's locale encoding, which is non-portable — on Linux/macOS that's typically UTF-8, but it's not guaranteed and can produce silent decode mismatches across environments. Making the encoding explicit removes that footgun. This brings our ruff config one step closer to alignment with dignified python. PLW1514 is a preview-status rule. The repo's ruff config sets `preview = true` with `explicit-preview-rules = true`, so adding the `"PLW"` prefix to `select` doesn't pull it in — the rule has to be listed by exact code (the existing `DOC102` entry follows the same pattern). This PR adds `"PLW1514"` in that same block in `dagster-oss/config/ruff.toml`. ## Changes - **`dagster-oss/config/ruff.toml`** — adds `"PLW1514"` to the `select` list in the explicit-preview block, with a comment explaining why it's listed by exact code. - **243 `.py` files across 244 file edits** — `ruff check --fix --unsafe-fixes` applied to every callsite: adds `encoding="utf-8"` to `open()` / `read_text()` / `write_text()` / `codecs.open()` calls in text mode. Followed by `ruff format` to re-wrap lines that became too long after the kwarg was inserted. Distribution by top-level directory: | Directory | Files touched | |-----------|---------------| | `dagster-oss/` | 171 | | `python_modules/` | 31 | | `dagster-cloud/` | 23 | | `scripts/` | 12 | | `public/` | 2 | | Other (`.buildkite`, `.github`, `infra`, `integration_tests`, `skills`) | 5 | The `dagster-oss/` portion will sync out to OSS. ## Why `--unsafe-fixes` is safe here Ruff marks PLW1514's fix as "unsafe" because hardcoding `encoding="utf-8"` could mask a real locale dependency on a non-UTF-8 system. I confirmed by file-extension audit that every affected callsite reads/writes UTF-8 text formats — `.py`, `.yaml`, `.json`, `.toml`, `.env`, `.md`, `.sql`, `.csv`, `.cfg`, `.log` — with zero binary-mode (`"rb"` / `"wb"`) calls touched (ruff only flags text-mode opens, so binary callsites are untouched by construction). ## Test Plan - [x] `uv run --frozen ruff check` — passes. - [x] `uv run --frozen ruff format --check` — passes. - [x] Verified violation count went from 576 → 0 after autofix. - [ ] CI green. Internal-RevId: 99b475233bb7bbcb2bffb07152a1eab5df2d365a
1 parent e817f49 commit fa3d023

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

scripts/release/bump.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ def update_plugin_version(plugin_path: Path, version: str) -> None:
2828
2929
Preserves JSON formatting (2-space indent, trailing newline).
3030
"""
31-
with plugin_path.open() as f:
31+
with plugin_path.open(encoding="utf-8") as f:
3232
data = json.load(f)
3333

3434
data["version"] = version
3535

36-
with plugin_path.open("w") as f:
36+
with plugin_path.open("w", encoding="utf-8") as f:
3737
json.dump(data, f, indent=2)
3838
f.write("\n")
3939

scripts/release/changelog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def extract_version_section(changelog_path: Path, version: str) -> str:
1616
Returns the content between the version header and the next version header,
1717
with empty category headers removed.
1818
"""
19-
with changelog_path.open() as f:
19+
with changelog_path.open(encoding="utf-8") as f:
2020
content = f.read()
2121

2222
# Pattern to match version section

0 commit comments

Comments
 (0)