From ff6c1ea5f30e3a4c85a90fcb6c587aafd01f28f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Franch?= Date: Tue, 13 Oct 2026 12:07:13 +0200 Subject: [PATCH] fix(stubgen): reconfigure stdout only when it supports it Callers that replace sys.stdout (test_stubgen redirect_stdout) have no reconfigure(). Co-Authored-By: Claude --- tools/stubgen.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/stubgen.py b/tools/stubgen.py index 444820d64..2c296b929 100644 --- a/tools/stubgen.py +++ b/tools/stubgen.py @@ -211,7 +211,8 @@ def main(argv=None): ap.add_argument("--td-out", required=False, default=None, help="output file for TechnicalDebt lines, which go in docs/dev/debt/MODULE.md, default stderr when code uses stdout, otherwise stdout") ap.add_argument("--td-only", action="store_true", help="print only TechnicalDebt lines, no code") args = ap.parse_args(argv) - sys.stdout.reconfigure(encoding="utf-8", newline="\n") + if hasattr(sys.stdout, "reconfigure"): + sys.stdout.reconfigure(encoding="utf-8", newline="\n") try: if not args.td_only and args.out and args.td_out and same_file(args.out, args.td_out): ap.error("--out and --td-out must name different files")