https://github.com/python/cpython/commit/0b72907cb5b781203938058da95692e12ed3eb73
commit: 0b72907cb5b781203938058da95692e12ed3eb73
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-09-24T16:47:40+02:00
summary:

gh-154757: No longer deprecate PyModule_GetFilename() (#158076)

files:
A Misc/NEWS.d/next/C_API/2026-09-24-14-14-34.gh-issue-154757.-b-Fs7.rst
M Doc/c-api/module.rst
M Doc/deprecations/c-api-pending-removal-in-future.rst
M Doc/whatsnew/3.16.rst
M Include/moduleobject.h

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 fe9f3028eab2b1c..3d3125ad17b126b 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.

_______________________________________________
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