Commit fa3d023
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: 99b475233bb7bbcb2bffb07152a1eab5df2d365a1 parent e817f49 commit fa3d023
2 files changed
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
0 commit comments