Skip to content

fix: read sources and write annotations as UTF-8 - #110

Merged
jimisola merged 1 commit into
mainfrom
fix/utf8-source-encoding
Nov 22, 2026
Merged

jimisola merged 1 commit into
mainfrom
fix/utf8-source-encoding

Conversation

@jimisola

Copy link
Copy Markdown
Member

Requested by Jimisola · project thread

Fixes #109.

Merge gate: do not merge before the macOS/Windows smoke-jobs PR (reqstool/reqstool-client#500) is merged and green. This changes Windows behaviour that CI cannot currently verify.

What & why

get_functions_and_classes opened sources with open(file_path, "r"), i.e. the platform locale encoding (cp1252 on Windows). A valid UTF-8 source with a byte cp1252 leaves undefined (e.g. Đ, 0x90) crashed the build hook with UnicodeDecodeError, which breaks hatch env create dev for reqstool-client on Windows.

  • Parse the raw bytes (ast.parse(Path(...).read_bytes())) so sources are decoded per PEP 263: UTF-8 by default, or the file's coding: declaration.
  • Write annotations.yml with encoding="utf-8".

Test plan

  • New: non-ASCII source processed in a child process with UTF-8 mode off and the C locale (mimics a default Windows setup). Fails without the fix.
  • New: a latin-1 coding: declaration is honoured. Fails without the fix.
  • hatch run dev:pytest tests/unit: 37 passed; black and flake8 clean
  • Windows runner not available here; the reqstool-client smoke jobs (#500) are the planned check.

Not covered: fullyQualifiedName is built with .replace("/", "."), which is wrong for Windows paths. Tracked separately.


Generated by Claude Code

open() without an encoding uses the platform locale, which is cp1252 on
Windows, so any source file containing a UTF-8 byte undefined in cp1252
crashed the build hook with UnicodeDecodeError. Parse the raw bytes so
ast decodes per PEP 263, and write annotations.yml explicitly as UTF-8.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mt2FAVc4k9yNuEdkfxHdQX
Signed-off-by: Jimisola Laursen <jimisola@jimisola.com>
@jimisola jimisola self-assigned this Nov 21, 2026
@jimisola
jimisola marked this pull request as ready for review November 22, 2026 01:10
@jimisola
jimisola merged commit e735a81 into main Nov 22, 2026
11 checks passed
@jimisola
jimisola deleted the fix/utf8-source-encoding branch November 22, 2026 01:10
jimisola added a commit that referenced this pull request Nov 22, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mt2FAXPoMhrbjtWKhBTwZM
Signed-off-by: Jimisola <jimisola@jimisola.com>
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.

fix: build crashes on Windows with UnicodeDecodeError (sources opened with locale encoding)

1 participant