Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f19a400

Browse files
committed
Issue #21088: Merge from 3.4.
2 parents 53d2c41 + 9147a96 commit f19a400

3 files changed

Lines changed: 45 additions & 12 deletions

File tree

Lib/test/test_curses.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import unittest
1919
from test.support import requires, import_module
20+
import inspect
2021
requires('curses')
2122

2223
# If either of these don't exist, skip the tests.
@@ -331,6 +332,34 @@ def test_encoding(stdscr):
331332
else:
332333
raise AssertionError("TypeError not raised")
333334

335+
def test_issue21088(stdscr):
336+
#
337+
# http://bugs.python.org/issue21088
338+
#
339+
# the bug:
340+
# when converting curses.window.addch to Argument Clinic
341+
# the first two parameters were switched.
342+
343+
# if someday we can represent the signature of addch
344+
# we will need to rewrite this test.
345+
try:
346+
signature = inspect.signature(stdscr.addch)
347+
self.assertFalse(signature)
348+
except ValueError:
349+
# not generating a signature is fine.
350+
pass
351+
352+
# So. No signature for addch.
353+
# But Argument Clinic gave us a human-readable equivalent
354+
# as the first line of the docstring. So we parse that,
355+
# and ensure that the parameters appear in the correct order.
356+
# Since this is parsing output from Argument Clinic, we can
357+
# be reasonably certain the generated parsing code will be
358+
# correct too.
359+
human_readable_signature = stdscr.addch.__doc__.split("\n")[0]
360+
offset = human_readable_signature.find("[y, x,]")
361+
assert offset >= 0, ""
362+
334363
def main(stdscr):
335364
curses.savetty()
336365
try:
@@ -344,6 +373,7 @@ def main(stdscr):
344373
test_unget_wch(stdscr)
345374
test_issue10570()
346375
test_encoding(stdscr)
376+
test_issue21088(stdscr)
347377
finally:
348378
curses.resetty()
349379

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ Core and Builtins
6969
Library
7070
-------
7171

72+
- Issue #21088: Bugfix for curses.window.addch() regression in 3.4.0.
73+
In porting to Argument Clinic, the first two arguments were reversed.
74+
7275
- Issue #10650: Remove the non-standard 'watchexp' parameter from the
7376
Decimal.quantize() method in the Python version. It had never been
7477
present in the C version.

Modules/_cursesmodule.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,10 @@ PyCursesWindow_Dealloc(PyCursesWindowObject *wo)
560560
curses.window.addch
561561
562562
[
563-
x: int
564-
X-coordinate.
565563
y: int
566564
Y-coordinate.
565+
x: int
566+
X-coordinate.
567567
]
568568
569569
ch: object
@@ -584,13 +584,13 @@ current settings for the window object.
584584
[clinic start generated code]*/
585585

586586
PyDoc_STRVAR(curses_window_addch__doc__,
587-
"addch([x, y,] ch, [attr])\n"
587+
"addch([y, x,] ch, [attr])\n"
588588
"Paint character ch at (y, x) with attributes attr.\n"
589589
"\n"
590-
" x\n"
591-
" X-coordinate.\n"
592590
" y\n"
593591
" Y-coordinate.\n"
592+
" x\n"
593+
" X-coordinate.\n"
594594
" ch\n"
595595
" Character to add.\n"
596596
" attr\n"
@@ -605,15 +605,15 @@ PyDoc_STRVAR(curses_window_addch__doc__,
605605
{"addch", (PyCFunction)curses_window_addch, METH_VARARGS, curses_window_addch__doc__},
606606

607607
static PyObject *
608-
curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr);
608+
curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, int x, PyObject *ch, int group_right_1, long attr);
609609

610610
static PyObject *
611611
curses_window_addch(PyCursesWindowObject *self, PyObject *args)
612612
{
613613
PyObject *return_value = NULL;
614614
int group_left_1 = 0;
615-
int x = 0;
616615
int y = 0;
616+
int x = 0;
617617
PyObject *ch;
618618
int group_right_1 = 0;
619619
long attr = 0;
@@ -629,12 +629,12 @@ curses_window_addch(PyCursesWindowObject *self, PyObject *args)
629629
group_right_1 = 1;
630630
break;
631631
case 3:
632-
if (!PyArg_ParseTuple(args, "iiO:addch", &x, &y, &ch))
632+
if (!PyArg_ParseTuple(args, "iiO:addch", &y, &x, &ch))
633633
goto exit;
634634
group_left_1 = 1;
635635
break;
636636
case 4:
637-
if (!PyArg_ParseTuple(args, "iiOl:addch", &x, &y, &ch, &attr))
637+
if (!PyArg_ParseTuple(args, "iiOl:addch", &y, &x, &ch, &attr))
638638
goto exit;
639639
group_right_1 = 1;
640640
group_left_1 = 1;
@@ -643,15 +643,15 @@ curses_window_addch(PyCursesWindowObject *self, PyObject *args)
643643
PyErr_SetString(PyExc_TypeError, "curses.window.addch requires 1 to 4 arguments");
644644
goto exit;
645645
}
646-
return_value = curses_window_addch_impl(self, group_left_1, x, y, ch, group_right_1, attr);
646+
return_value = curses_window_addch_impl(self, group_left_1, y, x, ch, group_right_1, attr);
647647

648648
exit:
649649
return return_value;
650650
}
651651

652652
static PyObject *
653-
curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int x, int y, PyObject *ch, int group_right_1, long attr)
654-
/*[clinic end generated code: output=43acb91a5c98f615 input=fe7e3711d5bbf1f6]*/
653+
curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, int x, PyObject *ch, int group_right_1, long attr)
654+
/*[clinic end generated code: output=d4b97cc287010c54 input=5a41efb34a2de338]*/
655655
{
656656
PyCursesWindowObject *cwself = (PyCursesWindowObject *)self;
657657
int coordinates_group = group_left_1;

0 commit comments

Comments
 (0)