Skip to content

Commit f842990

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.15] gh-87904: Document curses classes (GH-151643) (GH-152048)
Add docstrings for the curses.window, curses.error, curses.panel.panel and curses.panel.error classes. Document the panel class and its error exception in curses.panel.rst, using the real lowercase panel name. (cherry picked from commit 560ff8e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9bd0199 commit f842990

3 files changed

Lines changed: 64 additions & 20 deletions

File tree

Doc/library/curses.panel.rst

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ displayed. Panels can be added, moved up or down in the stack, and removed.
1616
Functions
1717
---------
1818

19+
The module :mod:`!curses.panel` defines the following exception:
20+
21+
22+
.. exception:: error
23+
24+
Exception raised when a curses panel library function returns an error.
25+
26+
1927
The module :mod:`!curses.panel` defines the following functions:
2028

2129

@@ -48,73 +56,91 @@ The module :mod:`!curses.panel` defines the following functions:
4856
Panel objects
4957
-------------
5058

51-
Panel objects, as returned by :func:`new_panel` above, are windows with a
52-
stacking order. There's always a window associated with a panel which determines
53-
the content, while the panel methods are responsible for the window's depth in
54-
the panel stack.
59+
.. raw:: html
60+
61+
<!-- Keep the old URL fragments working (see gh-89554) -->
62+
<span id='curses.panel.Panel.above'></span>
63+
<span id='curses.panel.Panel.below'></span>
64+
<span id='curses.panel.Panel.bottom'></span>
65+
<span id='curses.panel.Panel.hidden'></span>
66+
<span id='curses.panel.Panel.hide'></span>
67+
<span id='curses.panel.Panel.move'></span>
68+
<span id='curses.panel.Panel.replace'></span>
69+
<span id='curses.panel.Panel.set_userptr'></span>
70+
<span id='curses.panel.Panel.show'></span>
71+
<span id='curses.panel.Panel.top'></span>
72+
<span id='curses.panel.Panel.userptr'></span>
73+
<span id='curses.panel.Panel.window'></span>
74+
75+
.. class:: panel
76+
77+
Panel objects, as returned by :func:`new_panel` above, are windows with a
78+
stacking order. There's always a window associated with a panel which
79+
determines the content, while the panel methods are responsible for the
80+
window's depth in the panel stack.
5581

56-
Panel objects have the following methods:
82+
Panel objects have the following methods:
5783

5884

59-
.. method:: Panel.above()
85+
.. method:: panel.above()
6086

6187
Returns the panel above the current panel.
6288

6389

64-
.. method:: Panel.below()
90+
.. method:: panel.below()
6591

6692
Returns the panel below the current panel.
6793

6894

69-
.. method:: Panel.bottom()
95+
.. method:: panel.bottom()
7096

7197
Push the panel to the bottom of the stack.
7298

7399

74-
.. method:: Panel.hidden()
100+
.. method:: panel.hidden()
75101

76102
Returns ``True`` if the panel is hidden (not visible), ``False`` otherwise.
77103

78104

79-
.. method:: Panel.hide()
105+
.. method:: panel.hide()
80106

81107
Hide the panel. This does not delete the object, it just makes the window on
82108
screen invisible.
83109

84110

85-
.. method:: Panel.move(y, x)
111+
.. method:: panel.move(y, x)
86112

87113
Move the panel to the screen coordinates ``(y, x)``.
88114

89115

90-
.. method:: Panel.replace(win)
116+
.. method:: panel.replace(win)
91117

92118
Change the window associated with the panel to the window *win*.
93119

94120

95-
.. method:: Panel.set_userptr(obj)
121+
.. method:: panel.set_userptr(obj)
96122

97123
Set the panel's user pointer to *obj*. This is used to associate an arbitrary
98124
piece of data with the panel, and can be any Python object.
99125

100126

101-
.. method:: Panel.show()
127+
.. method:: panel.show()
102128

103129
Display the panel (which might have been hidden), placing it on top of
104130
the panel stack.
105131

106132

107-
.. method:: Panel.top()
133+
.. method:: panel.top()
108134

109135
Push panel to the top of the stack.
110136

111137

112-
.. method:: Panel.userptr()
138+
.. method:: panel.userptr()
113139

114140
Returns the user pointer for the panel. This might be any Python object.
115141

116142

117-
.. method:: Panel.window()
143+
.. method:: panel.window()
118144

119145
Returns the window object associated with the panel.
120146

Modules/_curses_panel.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,13 @@ static PyMethodDef PyCursesPanel_Methods[] = {
672672

673673
/* -------------------------------------------------------*/
674674

675+
PyDoc_STRVAR(PyCursesPanel_Type_doc,
676+
"A curses panel.\n"
677+
"\n"
678+
"Panel objects are returned by new_panel().");
679+
675680
static PyType_Slot PyCursesPanel_Type_slots[] = {
681+
{Py_tp_doc, (void *)PyCursesPanel_Type_doc},
676682
{Py_tp_clear, PyCursesPanel_Clear},
677683
{Py_tp_dealloc, PyCursesPanel_Dealloc},
678684
{Py_tp_traverse, PyCursesPanel_Traverse},
@@ -821,8 +827,10 @@ _curses_panel_exec(PyObject *mod)
821827
}
822828

823829
/* For exception _curses_panel.error */
824-
state->error = PyErr_NewException(
825-
"_curses_panel.error", NULL, NULL);
830+
state->error = PyErr_NewExceptionWithDoc(
831+
"_curses_panel.error",
832+
"Exception raised when a curses panel library function returns an error.",
833+
NULL, NULL);
826834

827835
if (PyModule_AddObjectRef(mod, "error", state->error) < 0) {
828836
return -1;

Modules/_cursesmodule.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3099,7 +3099,14 @@ static PyGetSetDef PyCursesWindow_getsets[] = {
30993099
{NULL, NULL, NULL, NULL } /* sentinel */
31003100
};
31013101

3102+
PyDoc_STRVAR(PyCursesWindow_Type_doc,
3103+
"A curses window.\n"
3104+
"\n"
3105+
"Window objects are returned by initscr() and newwin(), and by the\n"
3106+
"methods that create subwindows and pads.");
3107+
31023108
static PyType_Slot PyCursesWindow_Type_slots[] = {
3109+
{Py_tp_doc, (void *)PyCursesWindow_Type_doc},
31033110
{Py_tp_methods, PyCursesWindow_methods},
31043111
{Py_tp_getset, PyCursesWindow_getsets},
31053112
{Py_tp_dealloc, PyCursesWindow_dealloc},
@@ -5560,7 +5567,10 @@ cursesmodule_exec(PyObject *module)
55605567
}
55615568

55625569
/* For exception curses.error */
5563-
state->error = PyErr_NewException("_curses.error", NULL, NULL);
5570+
state->error = PyErr_NewExceptionWithDoc(
5571+
"_curses.error",
5572+
"Exception raised when a curses library function returns an error.",
5573+
NULL, NULL);
55645574
if (state->error == NULL) {
55655575
return -1;
55665576
}

0 commit comments

Comments
 (0)