from __future__ import annotations import sys def configure_utf8_stdio() -> None: for stream_name in ("stdout", "stderr"): stream = getattr(sys, stream_name, None) reconfigure = getattr(stream, "reconfigure", None) if callable(reconfigure): reconfigure(encoding="utf-8", errors="replace")