From b2faef24d0a6f950fe779c3e69e358c7847e31a7 Mon Sep 17 00:00:00 2001 From: Vyron Vasileiadis Date: Tue, 25 Aug 2026 11:21:28 +0300 Subject: [PATCH] gh-156347: Fix the documentation of curses `window.encoding` The attribute is not used to encode str arguments on a build linked against a wide-character version of the curses library, which is the default: str is passed to curses as wide characters and the encoding of the current locale determines the bytes. It is used on a narrow build, where it also decodes results. --- Doc/howto/curses.rst | 3 +-- Doc/library/curses.rst | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Doc/howto/curses.rst b/Doc/howto/curses.rst index 7bcf63c0b458962..f52461a08f44d73 100644 --- a/Doc/howto/curses.rst +++ b/Doc/howto/curses.rst @@ -298,8 +298,7 @@ the next subsection. The :meth:`~curses.window.addstr` method takes a Python string or bytestring as the value to be displayed. The contents of bytestrings are sent to the terminal as-is. Strings are encoded to bytes using -the value of the window's :attr:`~window.encoding` attribute; this defaults to -the default system encoding as returned by :func:`locale.getencoding`. +the encoding of the current locale (see :func:`locale.getencoding`). The :meth:`~curses.window.addch` methods take a character, which can be either a string of length 1, a bytestring of length 1, or an integer. diff --git a/Doc/library/curses.rst b/Doc/library/curses.rst index 858371f927f4fad..c763c497708a1ef 100644 --- a/Doc/library/curses.rst +++ b/Doc/library/curses.rst @@ -2002,7 +2002,11 @@ Other .. attribute:: window.encoding - Encoding used to encode method arguments (Unicode strings and characters). + Encoding used to encode and decode method arguments and results + (Unicode strings and characters) on a narrow build. It is not used on a + build linked against a wide-character version of the underlying curses + library, where strings are passed to curses as wide characters and the + encoding of the current locale determines the bytes. The encoding attribute is inherited from the parent window when a subwindow is created, for example with :meth:`window.subwin`. By default, current locale encoding is used (see :func:`locale.getencoding`).