Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Lib/test/test_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ def test_complexchar(self):
curses.complexchar('A', curses.A_BOLD))
self.assertNotEqual(curses.complexchar('A'), curses.complexchar('B'))
# repr() shows only a non-default attr/pair, and is a constructor call.
ns = {'_curses': sys.modules[type(cc).__module__]}
modname = type(cc).__module__
ns = {modname: sys.modules[modname]}
self.assertNotIn('attr=', repr(curses.complexchar('z')))
self.assertNotIn('pair=', repr(curses.complexchar('z')))
r = repr(curses.complexchar('A', curses.A_BOLD))
Expand Down Expand Up @@ -2187,6 +2188,24 @@ def test_has_extended_color_support(self):
r = curses.has_extended_color_support()
self.assertIsInstance(r, bool)

def test_type_names(self):
# The curses types report their public module rather than the
# underscore extension that implements them.
for name in 'window', 'complexchar', 'complexstr', 'screen', 'error':
tp = getattr(curses, name)
self.assertEqual(tp.__module__, 'curses')
self.assertEqual(tp.__qualname__, name)
self.assertEqual(tp.__name__, name)

@requires_curses_func('panel')
def test_panel_type_names(self):
import curses.panel
for name in 'panel', 'error':
tp = getattr(curses.panel, name)
self.assertEqual(tp.__module__, 'curses.panel')
self.assertEqual(tp.__qualname__, name)
self.assertEqual(tp.__name__, name)


class TestAscii(unittest.TestCase):

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The :mod:`curses` types and exceptions now report their public module in
:attr:`~type.__module__`, :func:`repr` and :func:`help` -- for example
``curses.window`` instead of ``_curses.window`` and ``curses.panel.error``
instead of ``_curses_panel.error``.
6 changes: 3 additions & 3 deletions Modules/_curses_panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ static PyType_Slot PyCursesPanel_Type_slots[] = {
};

static PyType_Spec PyCursesPanel_Type_spec = {
.name = "_curses_panel.panel",
.name = "curses.panel.panel",
.basicsize = sizeof(PyCursesPanelObject),
.flags = (
Py_TPFLAGS_DEFAULT
Expand Down Expand Up @@ -826,9 +826,9 @@ _curses_panel_exec(PyObject *mod)
return -1;
}

/* For exception _curses_panel.error */
/* For exception curses.panel.error */
state->error = PyErr_NewExceptionWithDoc(
"_curses_panel.error",
"curses.panel.error",
"Exception raised when a curses panel library function returns an error.",
NULL, NULL);

Expand Down
10 changes: 5 additions & 5 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4390,7 +4390,7 @@ static PyType_Slot PyCursesComplexChar_Type_slots[] = {
};

static PyType_Spec PyCursesComplexChar_Type_spec = {
.name = "_curses.complexchar",
.name = "curses.complexchar",
.basicsize = sizeof(PyCursesComplexCharObject),
.flags = Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_IMMUTABLETYPE
Expand All @@ -4415,7 +4415,7 @@ static PyType_Slot PyCursesComplexStr_Type_slots[] = {
};

static PyType_Spec PyCursesComplexStr_Type_spec = {
.name = "_curses.complexstr",
.name = "curses.complexstr",
.basicsize = offsetof(PyCursesComplexStrObject, cells),
.itemsize = sizeof(cchar_t),
.flags = Py_TPFLAGS_DEFAULT
Expand Down Expand Up @@ -4778,7 +4778,7 @@ static PyType_Slot PyCursesWindow_Type_slots[] = {
};

static PyType_Spec PyCursesWindow_Type_spec = {
.name = "_curses.window",
.name = "curses.window",
.basicsize = sizeof(PyCursesWindowObject),
.flags = Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_DISALLOW_INSTANTIATION
Expand Down Expand Up @@ -4954,7 +4954,7 @@ static PyType_Slot PyCursesScreen_Type_slots[] = {
};

static PyType_Spec PyCursesScreen_Type_spec = {
.name = "_curses.screen",
.name = "curses.screen",
.basicsize = sizeof(PyCursesScreenObject),
.flags = Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_DISALLOW_INSTANTIATION
Expand Down Expand Up @@ -8042,7 +8042,7 @@ cursesmodule_exec(PyObject *module)

/* For exception curses.error */
state->error = PyErr_NewExceptionWithDoc(
"_curses.error",
"curses.error",
"Exception raised when a curses library function returns an error.",
NULL, NULL);
if (state->error == NULL) {
Expand Down
Loading