Skip to content

Commit 410ec15

Browse files
Always reconfigure stdout
On Windows sys.stdout uses the surrogateescape error handler, which fails on lone surrogates produced by os.fsdecode(). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 916efb5 commit 410ec15

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

Lib/inspect.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,8 +3463,7 @@ def _main():
34633463

34643464
# The printed text can contain characters unencodable in the encoding
34653465
# of stdout, e.g. undecodable bytes of a file name.
3466-
if getattr(sys.stdout, 'errors', None) == 'strict':
3467-
sys.stdout.reconfigure(errors='backslashreplace')
3466+
sys.stdout.reconfigure(errors='backslashreplace')
34683467

34693468
parser = argparse.ArgumentParser()
34703469
parser.add_argument(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
``python -m inspect --details`` no longer fails with
1+
:program:`python -m inspect --details` no longer fails with
22
:exc:`UnicodeEncodeError` if the path of the module contains characters
33
unencodable in the encoding of :data:`sys.stdout`. Such characters are now
44
escaped with backslashes.

0 commit comments

Comments
 (0)