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 <noreply@anthropic.com>
This commit is contained in:
Adrià Franch 2026-10-13 12:07:13 +02:00
parent f6d5404f45
commit ff6c1ea5f3
1 changed files with 2 additions and 1 deletions

View File

@ -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")