From 3e9a5b022f01fa95b4485fcf2c0c87bfb9fff837 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Tue, 27 Jan 2026 00:15:16 -0700 Subject: [PATCH 1/4] gh-144257: document return values of PyModule_SetDocString (GH-144258) Co-authored-by: sobolevn --- Doc/c-api/module.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst index 431151b841ebb6..90f55add56bf52 100644 --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -1021,6 +1021,9 @@ or code that creates modules dynamically. ``PyModuleDef`` (such as when using :ref:`multi-phase-initialization`, ``PyModule_Create``, or ``PyModule_FromDefAndSpec``). + Return ``0`` on success. + Return ``-1`` with an exception set on error. + .. versionadded:: 3.5 .. c:function:: int PyUnstable_Module_SetGIL(PyObject *module, void *gil) From 487bd2dea538e36cb620dd9e0f298d731b9ede8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20S=C5=82awecki?= Date: Tue, 27 Jan 2026 10:49:05 +0100 Subject: [PATCH 2/4] gh-142119: Clarify that one `contextvars.Token` can only reset once in a lifetime (GH-143693) --- Doc/library/contextvars.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Doc/library/contextvars.rst b/Doc/library/contextvars.rst index 60376e730cb102..653d8b597c2362 100644 --- a/Doc/library/contextvars.rst +++ b/Doc/library/contextvars.rst @@ -119,13 +119,15 @@ Context Variables # After the reset call the var has no value again, so # var.get() would raise a LookupError. + The same *token* cannot be used twice. + .. class:: Token *Token* objects are returned by the :meth:`ContextVar.set` method. They can be passed to the :meth:`ContextVar.reset` method to revert the value of the variable to what it was before the corresponding - *set*. + *set*. A single token cannot reset a context variable more than once. Tokens support the :ref:`context manager protocol ` to automatically reset context variables. See :meth:`ContextVar.set`. From 17d447e993a0ff9b7d44786ceb2a8f9510638bfa Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Tue, 27 Jan 2026 02:05:09 -0800 Subject: [PATCH 3/4] gh-126014: test_makefile_test_folders: Ignore basically-empty directories (#140466) The code in test_makefile was attempting to ignore any non-interesting files, but missed some corners: 1. There is never a *file* called `__pycache__`. 2. A directory containing only a `__pycache__` subdirectory should be ignored. 3. A directory containing only hidden files should be ignored. Simplify this all into a couple of filters that let us check for empty lists. --- Lib/test/test_tools/test_makefile.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_tools/test_makefile.py b/Lib/test/test_tools/test_makefile.py index 4c7588d4d93fc3..31a516067394e1 100644 --- a/Lib/test/test_tools/test_makefile.py +++ b/Lib/test/test_tools/test_makefile.py @@ -48,15 +48,18 @@ def test_makefile_test_folders(self): if dirname == '__pycache__' or dirname.startswith('.'): dirs.clear() # do not process subfolders continue - # Skip empty dirs: + + # Skip empty dirs (ignoring hidden files and __pycache__): + files = [ + filename for filename in files + if not filename.startswith('.') + ] + dirs = [ + dirname for dirname in dirs + if not dirname.startswith('.') and dirname != "__pycache__" + ] if not dirs and not files: continue - # Skip dirs with hidden-only files: - if files and all( - filename.startswith('.') or filename == '__pycache__' - for filename in files - ): - continue relpath = os.path.relpath(dirpath, support.STDLIB_DIR) with self.subTest(relpath=relpath): From f2b5c206c788d3a5bf2ab7c63fb69d3b802646f4 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Tue, 27 Jan 2026 03:28:28 -0700 Subject: [PATCH 4/4] gh-143883: Use named parameters in PyModExport-related declarations & docs (GH-143884) --- Doc/c-api/module.rst | 10 +++++----- Include/moduleobject.h | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst index 90f55add56bf52..e8a6e09f5554ec 100644 --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -426,10 +426,10 @@ To retrieve the state from a given module, use the following functions: module state. -.. c:function:: int PyModule_GetStateSize(PyObject *, Py_ssize_t *result) +.. c:function:: int PyModule_GetStateSize(PyObject *module, Py_ssize_t *result) - Set *\*result* to the size of the module's state, as specified using - :c:macro:`Py_mod_state_size` (or :c:member:`PyModuleDef.m_size`), + Set *\*result* to the size of *module*'s state, as specified + using :c:macro:`Py_mod_state_size` (or :c:member:`PyModuleDef.m_size`), and return 0. On error, set *\*result* to -1, and return -1 with an exception set. @@ -597,7 +597,7 @@ A module's token -- and the *your_token* value to use in the above code -- is: .. c:function:: int PyModule_GetToken(PyObject *module, void** result) - Set *\*result* to the module's token and return 0. + Set *\*result* to the module token for *module* and return 0. On error, set *\*result* to NULL, and return -1 with an exception set. @@ -645,7 +645,7 @@ rather than from an extension's :ref:`export hook `. .. c:function:: int PyModule_Exec(PyObject *module) - Execute the :c:data:`Py_mod_exec` slot(s) of the given *module*. + Execute the :c:data:`Py_mod_exec` slot(s) of *module*. On success, return 0. On error, return -1 with an exception set. diff --git a/Include/moduleobject.h b/Include/moduleobject.h index e83bc395aa4618..d1dde7982ad50d 100644 --- a/Include/moduleobject.h +++ b/Include/moduleobject.h @@ -118,11 +118,11 @@ PyAPI_FUNC(int) PyUnstable_Module_SetGIL(PyObject *module, void *gil); #endif #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 15) -PyAPI_FUNC(PyObject *) PyModule_FromSlotsAndSpec(const PyModuleDef_Slot *, +PyAPI_FUNC(PyObject *) PyModule_FromSlotsAndSpec(const PyModuleDef_Slot *slots, PyObject *spec); -PyAPI_FUNC(int) PyModule_Exec(PyObject *mod); -PyAPI_FUNC(int) PyModule_GetStateSize(PyObject *mod, Py_ssize_t *result); -PyAPI_FUNC(int) PyModule_GetToken(PyObject *, void **result); +PyAPI_FUNC(int) PyModule_Exec(PyObject *module); +PyAPI_FUNC(int) PyModule_GetStateSize(PyObject *module, Py_ssize_t *result); +PyAPI_FUNC(int) PyModule_GetToken(PyObject *module, void **result); #endif #ifndef _Py_OPAQUE_PYOBJECT