Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0cc45ba

Browse files
committed
Issue #21398: Fix an unicode error in the pydoc pager when the documentation
contains characters not encodable to the stdout encoding.
1 parent 1c6970f commit 0cc45ba

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

Lib/pydoc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,9 @@ def bold(self, text):
14041404
def pager(text):
14051405
"""The first time this is called, determine what kind of pager to use."""
14061406
global pager
1407+
# Escape non-encodable characters to avoid encoding errors later
1408+
encoding = sys.getfilesystemencoding()
1409+
text = text.encode(encoding, 'backslashreplace').decode(encoding)
14071410
pager = getpager()
14081411
pager(text)
14091412

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Library
2626
- Issue #21396: Fix TextIOWrapper(..., write_through=True) to not force a
2727
flush() on the underlying binary stream. Patch by akira.
2828

29+
- Issue #21398: Fix an unicode error in the pydoc pager when the documentation
30+
contains characters not encodable to the stdout encoding.
31+
2932
Tests
3033
-----
3134

0 commit comments

Comments
 (0)