Skip to content

fix: add explicit UTF-8 encoding to read_text() calls (#776)#946

Open
mvalentsev wants to merge 1 commit intoMemPalace:developfrom
mvalentsev:fix/utf8-read-text
Open

fix: add explicit UTF-8 encoding to read_text() calls (#776)#946
mvalentsev wants to merge 1 commit intoMemPalace:developfrom
mvalentsev:fix/utf8-read-text

Conversation

@mvalentsev
Copy link
Copy Markdown
Contributor

@mvalentsev mvalentsev commented Apr 16, 2026

What

Path.read_text() without encoding defaults to platform encoding on Windows. On locales like GBK this breaks any file written as UTF-8.

8 call sites fixed across 5 files:

  • tests/test_onboarding.py (4x) -- the reported bug: onboarding writes UTF-8 (lines 315, 362), tests read without encoding
  • tests/test_instructions_cli.py (1x) -- reads UTF-8 markdown
  • mempalace/entity_registry.py (1x) -- reads JSON with non-ASCII entity names
  • mempalace/split_mega_files.py (1x) -- reads JSON with non-ASCII known names
  • mempalace/instructions_cli.py (1x) -- prints UTF-8 markdown to terminal

Why explicit encoding, not PYTHONUTF8

Considered alternatives:

  • PYTHONUTF8=1 in CI -- must be set before Python starts, so it can't go in conftest.py. Works for CI but doesn't fix local test runs on Windows. Also a global override of all I/O which can mask real encoding bugs.
  • PEP 686 (Python 3.15) -- UTF-8 will become the default, but mempalace supports >=3.9 so that's years away.
  • Explicit encoding="utf-8" per call -- PEP 597 recommendation. Works on all Python versions, all platforms, no env setup needed.

Test plan

  • CI passes on all platforms (especially test-windows)
  • pytest tests/test_onboarding.py tests/test_instructions_cli.py -v -- 52 passed locally

On Windows with non-UTF-8 locale (e.g. GBK), Path.read_text() defaults
to platform encoding, breaking onboarding tests and any source code that
reads JSON/markdown with non-ASCII content.

5 files, 8 call sites fixed.
@mvalentsev mvalentsev marked this pull request as ready for review April 16, 2026 11:10
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