From 3f68a0d4e5fb34c4028b83709c5f27f3c33da22f Mon Sep 17 00:00:00 2001 From: UmranPros <152087084+umran666@users.noreply.github.com> Date: Thu, 18 Jun 2026 18:16:43 +0530 Subject: [PATCH] fix: resolve UnicodeEncodeError on Windows during model evaluation (#389) * fix: ensure utf-8 encoding for standard output and error to prevent UnicodeEncodeError on Windows * fix: address bot review feedback * refactor: deduplicate stream reconfiguration loop --- src/heretic/main.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/heretic/main.py b/src/heretic/main.py index fbc18c3..d460b53 100644 --- a/src/heretic/main.py +++ b/src/heretic/main.py @@ -5,6 +5,14 @@ import sys +# Ensure standard output/error use UTF-8 instead of system default charmap (e.g. cp1252 on Windows). +for stream in (sys.stdout, sys.stderr): + if ( + hasattr(stream, "reconfigure") + and (getattr(stream, "encoding", "") or "").lower() != "utf-8" + ): + stream.reconfigure(encoding="utf-8") # type: ignore + from .config import Settings