From 157e388ae7d42f04eb51243e20b62d2c59cf29eb Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 15 Sep 2026 14:13:08 +0300 Subject: [PATCH] gh-157546: Add missing docstrings in curses The Python wrappers initscr(), newterm() and start_color() now use the docstrings of the wrapped C functions, and the screen type has a docstring. --- Lib/curses/__init__.py | 4 ++++ Modules/_cursesmodule.c | 11 +++++++++-- Modules/clinic/_cursesmodule.c.h | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Lib/curses/__init__.py b/Lib/curses/__init__.py index 1e372ecdc83139..bdc342ed1c25ef 100644 --- a/Lib/curses/__init__.py +++ b/Lib/curses/__init__.py @@ -11,6 +11,7 @@ """ from _curses import * +import _curses import os as _os import sys as _sys @@ -33,6 +34,7 @@ def initscr(): if key.startswith(('ACS_', 'WACS_')) or key in ('LINES', 'COLS'): setattr(curses, key, value) return stdscr +initscr.__doc__ = _curses.initscr.__doc__ # newterm() is wrapped for the same reason as initscr(): the ACS_* and WACS_* # constants and LINES/COLS only become available once a terminal is @@ -50,6 +52,7 @@ def newterm(type=None, fd=None, infd=None, /): if key.startswith(('ACS_', 'WACS_')) or key in ('LINES', 'COLS'): setattr(curses, key, value) return screen + newterm.__doc__ = _curses.newterm.__doc__ # This is a similar wrapper for start_color(), which adds the COLORS and # COLOR_PAIRS variables which are only available after start_color() is @@ -60,6 +63,7 @@ def start_color(): _curses.start_color() curses.COLORS = _curses.COLORS curses.COLOR_PAIRS = _curses.COLOR_PAIRS +start_color.__doc__ = _curses.start_color.__doc__ # Import Python has_key() implementation if _curses doesn't contain has_key() diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 24cfbcdd503cee..69f7a65d8ca695 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -5534,7 +5534,14 @@ static PyMethodDef PyCursesScreen_methods[] = { {NULL, NULL} /* sentinel */ }; +PyDoc_STRVAR(PyCursesScreen_Type_doc, +"A curses screen.\n" +"\n" +"Screen objects are returned by newterm() and new_prescr(), and represent\n" +"a terminal together with its standard window, stdscr."); + static PyType_Slot PyCursesScreen_Type_slots[] = { + {Py_tp_doc, (void *)PyCursesScreen_Type_doc}, {Py_tp_methods, PyCursesScreen_methods}, {Py_tp_getset, PyCursesScreen_getsets}, {Py_tp_dealloc, PyCursesScreen_dealloc}, @@ -6929,12 +6936,12 @@ _curses.initscr Initialize the library. -Return a WindowObject which represents the whole screen. +Return a window object which represents the whole screen. [clinic start generated code]*/ static PyObject * _curses_initscr_impl(PyObject *module) -/*[clinic end generated code: output=619fb68443810b7b input=514f4bce1821f6b5]*/ +/*[clinic end generated code: output=619fb68443810b7b input=e2bf3a061b7d948a]*/ { WINDOW *win; diff --git a/Modules/clinic/_cursesmodule.c.h b/Modules/clinic/_cursesmodule.c.h index 256d7ea9255948..7b83727a20b68a 100644 --- a/Modules/clinic/_cursesmodule.c.h +++ b/Modules/clinic/_cursesmodule.c.h @@ -4191,7 +4191,7 @@ PyDoc_STRVAR(_curses_initscr__doc__, "\n" "Initialize the library.\n" "\n" -"Return a WindowObject which represents the whole screen."); +"Return a window object which represents the whole screen."); #define _CURSES_INITSCR_METHODDEF \ {"initscr", (PyCFunction)_curses_initscr, METH_NOARGS, _curses_initscr__doc__}, @@ -6749,4 +6749,4 @@ _curses_has_extended_color_support(PyObject *module, PyObject *Py_UNUSED(ignored #ifndef _CURSES_ASSUME_DEFAULT_COLORS_METHODDEF #define _CURSES_ASSUME_DEFAULT_COLORS_METHODDEF #endif /* !defined(_CURSES_ASSUME_DEFAULT_COLORS_METHODDEF) */ -/*[clinic end generated code: output=bbaebaa6961d42d3 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=cc7b5de1c82ae56b input=a9049054013a1b77]*/