Issue #21088: Bugfix for curses.window.addch() regression in 3.4.0.

In porting to Argument Clinic, the first two arguments were reversed.
This commit is contained in:
Larry Hastings 2014-05-04 04:41:18 -07:00
parent 88b5b6ddf6
commit 9147a9697a
3 changed files with 45 additions and 12 deletions

View File

@ -17,6 +17,7 @@ import sys, tempfile, os
import unittest import unittest
from test.support import requires, import_module from test.support import requires, import_module
import inspect
requires('curses') requires('curses')
# If either of these don't exist, skip the tests. # If either of these don't exist, skip the tests.
@ -331,6 +332,34 @@ def test_encoding(stdscr):
else: else:
raise AssertionError("TypeError not raised") raise AssertionError("TypeError not raised")
def test_issue21088(stdscr):
#
# http://bugs.python.org/issue21088
#
# the bug:
# when converting curses.window.addch to Argument Clinic
# the first two parameters were switched.
# if someday we can represent the signature of addch
# we will need to rewrite this test.
try:
signature = inspect.signature(stdscr.addch)
self.assertFalse(signature)
except ValueError:
# not generating a signature is fine.
pass
# So. No signature for addch.
# But Argument Clinic gave us a human-readable equivalent
# as the first line of the docstring. So we parse that,
# and ensure that the parameters appear in the correct order.
# Since this is parsing output from Argument Clinic, we can
# be reasonably certain the generated parsing code will be
# correct too.
human_readable_signature = stdscr.addch.__doc__.split("\n")[0]
offset = human_readable_signature.find("[y, x,]")
assert offset >= 0, ""
def main(stdscr): def main(stdscr):
curses.savetty() curses.savetty()
try: try:
@ -344,6 +373,7 @@ def main(stdscr):
test_unget_wch(stdscr) test_unget_wch(stdscr)
test_issue10570() test_issue10570()
test_encoding(stdscr) test_encoding(stdscr)
test_issue21088(stdscr)
finally: finally:
curses.resetty() curses.resetty()

View File

@ -39,6 +39,9 @@ Core and Builtins
Library Library
------- -------
- Issue #21088: Bugfix for curses.window.addch() regression in 3.4.0.
In porting to Argument Clinic, the first two arguments were reversed.
- Issue #21321: itertools.islice() now releases the reference to the source - Issue #21321: itertools.islice() now releases the reference to the source
iterator when the slice is exhausted. Patch by Anton Afanasyev. iterator when the slice is exhausted. Patch by Anton Afanasyev.

View File

@ -560,10 +560,10 @@ PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
curses.window.addch curses.window.addch
[ [
x: int
X-coordinate.
y: int y: int
Y-coordinate. Y-coordinate.
x: int
X-coordinate.
] ]
ch: object ch: object
@ -584,13 +584,13 @@ current settings for the window object.
[clinic start generated code]*/ [clinic start generated code]*/
PyDoc_STRVAR(curses_window_addch__doc__, PyDoc_STRVAR(curses_window_addch__doc__,
"addch([x, y,] ch, [attr])\n" "addch([y, x,] ch, [attr])\n"
"Paint character ch at (y, x) with attributes attr.\n" "Paint character ch at (y, x) with attributes attr.\n"
"\n" "\n"
" x\n"
" X-coordinate.\n"
" y\n" " y\n"
" Y-coordinate.\n" " Y-coordinate.\n"
" x\n"
" X-coordinate.\n"
" ch\n" " ch\n"
" Character to add.\n" " Character to add.\n"
" attr\n" " attr\n"
@ -605,15 +605,15 @@ PyDoc_STRVAR(curses_window_addch__doc__,
{"addch", (PyCFunction)curses_window_addch, METH_VARARGS, curses_window_addch__doc__}, {"addch", (PyCFunction)curses_window_addch, METH_VARARGS, curses_window_addch__doc__},
static PyObject * static PyObject *
curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr); curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, int x, PyObject *ch, int group_right_1, long attr);
static PyObject * static PyObject *
curses_window_addch(PyCursesWindowObject *self, PyObject *args) curses_window_addch(PyCursesWindowObject *self, PyObject *args)
{ {
PyObject *return_value = NULL; PyObject *return_value = NULL;
int group_left_1 = 0; int group_left_1 = 0;
int x = 0;
int y = 0; int y = 0;
int x = 0;
PyObject *ch; PyObject *ch;
int group_right_1 = 0; int group_right_1 = 0;
long attr = 0; long attr = 0;
@ -629,12 +629,12 @@ curses_window_addch(PyCursesWindowObject *self, PyObject *args)
group_right_1 = 1; group_right_1 = 1;
break; break;
case 3: case 3:
if (!PyArg_ParseTuple(args, "iiO:addch", &x, &y, &ch)) if (!PyArg_ParseTuple(args, "iiO:addch", &y, &x, &ch))
goto exit; goto exit;
group_left_1 = 1; group_left_1 = 1;
break; break;
case 4: case 4:
if (!PyArg_ParseTuple(args, "iiOl:addch", &x, &y, &ch, &attr)) if (!PyArg_ParseTuple(args, "iiOl:addch", &y, &x, &ch, &attr))
goto exit; goto exit;
group_right_1 = 1; group_right_1 = 1;
group_left_1 = 1; group_left_1 = 1;
@ -643,15 +643,15 @@ curses_window_addch(PyCursesWindowObject *self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "curses.window.addch requires 1 to 4 arguments"); PyErr_SetString(PyExc_TypeError, "curses.window.addch requires 1 to 4 arguments");
goto exit; goto exit;
} }
return_value = curses_window_addch_impl(self, group_left_1, x, y, ch, group_right_1, attr); return_value = curses_window_addch_impl(self, group_left_1, y, x, ch, group_right_1, attr);
exit: exit:
return return_value; return return_value;
} }
static PyObject * static PyObject *
curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr) curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, int x, PyObject *ch, int group_right_1, long attr)
/*[clinic end generated code: output=43acb91a5c98f615 input=fe7e3711d5bbf1f6]*/ /*[clinic end generated code: output=d4b97cc287010c54 input=5a41efb34a2de338]*/
{ {
PyCursesWindowObject *cwself = (PyCursesWindowObject *)self; PyCursesWindowObject *cwself = (PyCursesWindowObject *)self;
int coordinates_group = group_left_1; int coordinates_group = group_left_1;