From 12920e515a498a1d69f2f532555b5ca78c7001d5 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 24 Sep 2026 14:13:48 +0200 Subject: [PATCH] gh-154757: No longer deprecate PyModule_GetFilename() --- Doc/c-api/module.rst | 5 ++--- Doc/deprecations/c-api-pending-removal-in-future.rst | 2 -- Doc/whatsnew/3.16.rst | 4 ++++ Include/moduleobject.h | 2 +- .../C_API/2026-09-24-14-14-34.gh-issue-154757.-b-Fs7.rst | 3 +++ 5 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/C_API/2026-09-24-14-14-34.gh-issue-154757.-b-Fs7.rst diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst index e4664ef815f567c..cf04e4c1ed63a10 100644 --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -128,9 +128,8 @@ Module Objects The returned buffer is only valid until the module's :py:attr:`~module.__file__` attribute is reassigned or the module is destroyed. - .. deprecated:: 3.2 - :c:func:`PyModule_GetFilename` raises :exc:`UnicodeEncodeError` on - unencodable filenames, use :c:func:`PyModule_GetFilenameObject` instead. + :c:func:`PyModule_GetFilename` raises :exc:`UnicodeEncodeError` on + unencodable filenames, use :c:func:`PyModule_GetFilenameObject` instead. .. _c_module_slots: diff --git a/Doc/deprecations/c-api-pending-removal-in-future.rst b/Doc/deprecations/c-api-pending-removal-in-future.rst index 841d1b455b6bec6..273d85bd9332455 100644 --- a/Doc/deprecations/c-api-pending-removal-in-future.rst +++ b/Doc/deprecations/c-api-pending-removal-in-future.rst @@ -12,8 +12,6 @@ although there is currently no date scheduled for their removal. Use :c:func:`PyErr_GetRaisedException` instead. * :c:func:`PyErr_Restore`: Use :c:func:`PyErr_SetRaisedException` instead. -* :c:func:`PyModule_GetFilename`: - Use :c:func:`PyModule_GetFilenameObject` instead. * :c:func:`PyOS_AfterFork`: Use :c:func:`PyOS_AfterFork_Child` instead. * :c:func:`PySlice_GetIndicesEx`: diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index c76681261f6746d..1d0971cbb4379da 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -1128,6 +1128,10 @@ Deprecated C APIs and :c:func:`PyAsyncGen_New` are deprecated. They are scheduled for removal in 3.18. +* :c:func:`PyModule_GetFilename` is no longer deprecated, but using + :c:func:`PyModule_GetFilenameObject` instead is still recommended. + (Contributed by Victor Stinner in :gh:`154757`.) + .. Add C API deprecations above alphabetically, not here at the end. .. include:: ../deprecations/c-api-pending-removal-in-3.18.rst diff --git a/Include/moduleobject.h b/Include/moduleobject.h index 88c66672ff164a8..3e12839ec509811 100644 --- a/Include/moduleobject.h +++ b/Include/moduleobject.h @@ -25,7 +25,7 @@ PyAPI_FUNC(PyObject *) PyModule_GetDict(PyObject *); PyAPI_FUNC(PyObject *) PyModule_GetNameObject(PyObject *); #endif PyAPI_FUNC(const char *) PyModule_GetName(PyObject *); -Py_DEPRECATED(3.2) PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *); +PyAPI_FUNC(const char *) PyModule_GetFilename(PyObject *); PyAPI_FUNC(PyObject *) PyModule_GetFilenameObject(PyObject *); PyAPI_FUNC(PyModuleDef*) PyModule_GetDef(PyObject*); PyAPI_FUNC(void*) PyModule_GetState(PyObject*); diff --git a/Misc/NEWS.d/next/C_API/2026-09-24-14-14-34.gh-issue-154757.-b-Fs7.rst b/Misc/NEWS.d/next/C_API/2026-09-24-14-14-34.gh-issue-154757.-b-Fs7.rst new file mode 100644 index 000000000000000..2e28e24ebff0a77 --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2026-09-24-14-14-34.gh-issue-154757.-b-Fs7.rst @@ -0,0 +1,3 @@ +:c:func:`PyModule_GetFilename` is no longer deprecated, but using +:c:func:`PyModule_GetFilenameObject` instead is still recommended. Patch by +Victor Stinner.