Skip to content

Commit 3b3f5f2

Browse files
committed
remove dead Argument Clinic for _curses.window.instr
1 parent a670d54 commit 3b3f5f2

File tree

1 file changed

+33
-52
lines changed

1 file changed

+33
-52
lines changed

Modules/_cursesmodule.c

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,66 +2021,44 @@ _curses_window_inch_impl(PyCursesWindowObject *self, int group_right_1,
20212021
return rtn;
20222022
}
20232023

2024-
/*[-clinic input]
2025-
_curses.window.instr
2026-
2027-
[
2028-
y: int
2029-
Y-coordinate.
2030-
x: int
2031-
X-coordinate.
2032-
]
2033-
n: int = 1023
2034-
Maximal number of characters.
2035-
/
2036-
2037-
Return a string of characters, extracted from the window.
2024+
PyDoc_STRVAR(_curses_window_instr__doc__,
2025+
"instr([y, x,] n=1023)\n"
2026+
"Return a string of characters, extracted from the window.\n"
2027+
"\n"
2028+
" y\n"
2029+
" Y-coordinate.\n"
2030+
" x\n"
2031+
" X-coordinate.\n"
2032+
" n\n"
2033+
" Maximal number of characters.\n"
2034+
"\n"
2035+
"Return a string of characters, extracted from the window starting at the\n"
2036+
"current cursor position, or at y, x if specified. Attributes are stripped\n"
2037+
"from the characters. If n is specified, instr() returns a string at most\n"
2038+
"n characters long (exclusive of the trailing NUL).");
20382039

2039-
Return a string of characters, extracted from the window starting at the
2040-
current cursor position, or at y, x if specified. Attributes are stripped
2041-
from the characters. If n is specified, instr() returns a string at most
2042-
n characters long (exclusive of the trailing NUL).
2043-
[-clinic start generated code]*/
20442040
static PyObject *
2045-
PyCursesWindow_InStr(PyObject *op, PyObject *args)
2041+
PyCursesWindow_instr(PyObject *op, PyObject *args)
20462042
{
20472043
PyCursesWindowObject *self = _PyCursesWindowObject_CAST(op);
2048-
2049-
int x, y, n;
2044+
int use_xy = 0, y = 0, x = 0;
2045+
unsigned int n = 1023;
20502046
char rtn[1024]; /* This should be big enough.. I hope */
20512047
int rtn2;
20522048

2053-
switch (PyTuple_Size(args)) {
2054-
case 0:
2055-
rtn2 = winnstr(self->win,rtn, 1023);
2056-
break;
2057-
case 1:
2058-
if (!PyArg_ParseTuple(args,"i;n", &n))
2059-
return NULL;
2060-
if (n < 0) {
2061-
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
2062-
return NULL;
2063-
}
2064-
rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023));
2065-
break;
2066-
case 2:
2067-
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
2068-
return NULL;
2069-
rtn2 = mvwinnstr(self->win,y,x,rtn,1023);
2070-
break;
2071-
case 3:
2072-
if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
2073-
return NULL;
2074-
if (n < 0) {
2075-
PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative");
2076-
return NULL;
2077-
}
2078-
rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023));
2079-
break;
2080-
default:
2081-
PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
2049+
if (!curses_clinic_parse_optional_xy_n(args, &y, &x, &n, &use_xy,
2050+
"_curses.window.instr"))
2051+
{
20822052
return NULL;
20832053
}
2054+
2055+
n = Py_MIN(n, 1023);
2056+
if (use_xy) {
2057+
rtn2 = mvwinnstr(self->win, y, x, rtn, n);
2058+
}
2059+
else {
2060+
rtn2 = winnstr(self->win, rtn, n);
2061+
}
20842062
if (rtn2 == ERR)
20852063
rtn[0] = 0;
20862064
return PyBytes_FromString(rtn);
@@ -2868,7 +2846,10 @@ static PyMethodDef PyCursesWindow_methods[] = {
28682846
{"insertln", PyCursesWindow_winsertln, METH_NOARGS},
28692847
_CURSES_WINDOW_INSNSTR_METHODDEF
28702848
_CURSES_WINDOW_INSSTR_METHODDEF
2871-
{"instr", PyCursesWindow_InStr, METH_VARARGS},
2849+
{
2850+
"instr", PyCursesWindow_instr, METH_VARARGS,
2851+
_curses_window_instr__doc__
2852+
},
28722853
_CURSES_WINDOW_IS_LINETOUCHED_METHODDEF
28732854
{"is_wintouched", PyCursesWindow_is_wintouched, METH_NOARGS},
28742855
{"keypad", PyCursesWindow_keypad, METH_VARARGS},

0 commit comments

Comments
 (0)