https://github.com/python/cpython/commit/0ed67114659d03702a5ad1a25db6f2b9d0aae39b
commit: 0ed67114659d03702a5ad1a25db6f2b9d0aae39b
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-06-27T23:23:55+03:00
summary:

gh-152332: Add the curses.term_attrs() function (GH-152333)

term_attrs() returns the video attributes supported by the terminal as
WA_* values, the counterpart of termattrs() for the A_* values.

Co-authored-by: Claude Opus 4.8 <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-06-26-22-15-00.gh-issue-152332.Lp3WqN.rst
M Doc/library/curses.rst
M Doc/whatsnew/3.16.rst
M Lib/test/test_curses.py
M Modules/_cursesmodule.c
M Modules/clinic/_cursesmodule.c.h

diff --git a/Doc/library/curses.rst b/Doc/library/curses.rst
index 60c60a9edeec49c..71eadfd5ca2ad70 100644
--- a/Doc/library/curses.rst
+++ b/Doc/library/curses.rst
@@ -841,6 +841,14 @@ The module :mod:`!curses` defines the following functions:
    appearance of the screen.
 
 
+.. function:: term_attrs()
+
+   Like :func:`termattrs`, but return the attributes as :ref:`WA_*
+   <curses-wa-constants>` values rather than ``A_*`` values.
+
+   .. versionadded:: next
+
+
 .. function:: termname()
 
    Return the value of the environment variable :envvar:`TERM`, as a bytes 
object,
diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst
index 7841fa56cc5952c..90ab3ee630b165e 100644
--- a/Doc/whatsnew/3.16.rst
+++ b/Doc/whatsnew/3.16.rst
@@ -165,6 +165,11 @@ curses
   :func:`~curses.scr_set`, which dump the whole screen to a file and restore 
it.
   (Contributed by Serhiy Storchaka in :gh:`152260`.)
 
+* Add the :func:`curses.term_attrs` function, which returns the supported
+  video attributes as :ref:`WA_* <curses-wa-constants>` values, the
+  counterpart of :func:`curses.termattrs`.
+  (Contributed by Serhiy Storchaka in :gh:`152332`.)
+
 * Add the :mod:`curses` key-management functions :func:`~curses.define_key`,
   :func:`~curses.key_defined` and :func:`~curses.keyok`, available when built
   against an ncurses with ``NCURSES_EXT_FUNCS``.
diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py
index d9e9cf394fa86fb..5f01ac6546a0ba0 100644
--- a/Lib/test/test_curses.py
+++ b/Lib/test/test_curses.py
@@ -1512,13 +1512,13 @@ def test_misc_module_funcs(self):
         curses.newpad(50, 50)
 
     def test_env_queries(self):
-        # TODO: term_attrs()
         self.assertIsInstance(curses.termname(), bytes)
         self.assertIsInstance(curses.longname(), bytes)
         self.assertIsInstance(curses.baudrate(), int)
         self.assertIsInstance(curses.has_ic(), bool)
         self.assertIsInstance(curses.has_il(), bool)
         self.assertIsInstance(curses.termattrs(), int)
+        self.assertIsInstance(curses.term_attrs(), int)
 
         c = curses.killchar()
         self.assertIsInstance(c, bytes)
diff --git 
a/Misc/NEWS.d/next/Library/2026-06-26-22-15-00.gh-issue-152332.Lp3WqN.rst 
b/Misc/NEWS.d/next/Library/2026-06-26-22-15-00.gh-issue-152332.Lp3WqN.rst
new file mode 100644
index 000000000000000..32875cdac5c9d0c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-06-26-22-15-00.gh-issue-152332.Lp3WqN.rst
@@ -0,0 +1,2 @@
+Add the :func:`curses.term_attrs` function, the counterpart of
+:func:`curses.termattrs` for the ``WA_*`` attributes.
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 76e93784b94d466..5e50f9b1e0b2384 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -7347,6 +7347,24 @@ _curses_termattrs_impl(PyObject *module)
 /*[clinic end generated code: output=b06f437fce1b6fc4 input=0559882a04f84d1d]*/
 NoArgReturnIntFunctionBody(termattrs)
 
+/*[clinic input]
+_curses.term_attrs
+
+Return a logical OR of all video attributes supported by the terminal.
+
+The attributes are WA_* values, the extended-attribute counterparts of
+the A_* values returned by termattrs().
+[clinic start generated code]*/
+
+static PyObject *
+_curses_term_attrs_impl(PyObject *module)
+/*[clinic end generated code: output=c559daa1370948d6 input=963136fd17ab797a]*/
+{
+    PyCursesStatefulInitialised(module);
+
+    return PyLong_FromUnsignedLong(term_attrs());
+}
+
 /*[clinic input]
 @permit_long_summary
 _curses.termname
@@ -7905,6 +7923,7 @@ static PyMethodDef cursesmodule_methods[] = {
     _CURSES_SETUPTERM_METHODDEF
     _CURSES_START_COLOR_METHODDEF
     _CURSES_TERMATTRS_METHODDEF
+    _CURSES_TERM_ATTRS_METHODDEF
     _CURSES_TERMNAME_METHODDEF
     _CURSES_TIGETFLAG_METHODDEF
     _CURSES_TIGETNUM_METHODDEF
diff --git a/Modules/clinic/_cursesmodule.c.h b/Modules/clinic/_cursesmodule.c.h
index a4a7791fa6adcd6..1c05a125fd1cc6c 100644
--- a/Modules/clinic/_cursesmodule.c.h
+++ b/Modules/clinic/_cursesmodule.c.h
@@ -5073,6 +5073,27 @@ _curses_termattrs(PyObject *module, PyObject 
*Py_UNUSED(ignored))
     return _curses_termattrs_impl(module);
 }
 
+PyDoc_STRVAR(_curses_term_attrs__doc__,
+"term_attrs($module, /)\n"
+"--\n"
+"\n"
+"Return a logical OR of all video attributes supported by the terminal.\n"
+"\n"
+"The attributes are WA_* values, the extended-attribute counterparts of\n"
+"the A_* values returned by termattrs().");
+
+#define _CURSES_TERM_ATTRS_METHODDEF    \
+    {"term_attrs", (PyCFunction)_curses_term_attrs, METH_NOARGS, 
_curses_term_attrs__doc__},
+
+static PyObject *
+_curses_term_attrs_impl(PyObject *module);
+
+static PyObject *
+_curses_term_attrs(PyObject *module, PyObject *Py_UNUSED(ignored))
+{
+    return _curses_term_attrs_impl(module);
+}
+
 PyDoc_STRVAR(_curses_termname__doc__,
 "termname($module, /)\n"
 "--\n"
@@ -5645,4 +5666,4 @@ _curses_has_extended_color_support(PyObject *module, 
PyObject *Py_UNUSED(ignored
 #ifndef _CURSES_ASSUME_DEFAULT_COLORS_METHODDEF
     #define _CURSES_ASSUME_DEFAULT_COLORS_METHODDEF
 #endif /* !defined(_CURSES_ASSUME_DEFAULT_COLORS_METHODDEF) */
-/*[clinic end generated code: output=01cb1ecb396881c9 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=976a6629bfe58a3d input=a9049054013a1b77]*/

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to