From cae8dc6b6b71cb9f9d703ed098687ed8dfd82528 Mon Sep 17 00:00:00 2001 From: Cheukting Date: Tue, 17 Feb 2026 18:35:09 +0000 Subject: [PATCH 1/4] Deprecate and remove `Py_TRACE_REFS` support (unsupported from Python 3.13). --- pyo3-build-config/src/impl_.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index 167013f5c42..0a28fa80ca7 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -1147,6 +1147,7 @@ pub fn cross_compiling_from_cargo_env() -> Result> { pub enum BuildFlag { Py_DEBUG, Py_REF_DEBUG, + #[deprecated = "Not supported since Python 3.13"] Py_TRACE_REFS, Py_GIL_DISABLED, COUNT_ALLOCS, @@ -1168,7 +1169,6 @@ impl FromStr for BuildFlag { match s { "Py_DEBUG" => Ok(BuildFlag::Py_DEBUG), "Py_REF_DEBUG" => Ok(BuildFlag::Py_REF_DEBUG), - "Py_TRACE_REFS" => Ok(BuildFlag::Py_TRACE_REFS), "Py_GIL_DISABLED" => Ok(BuildFlag::Py_GIL_DISABLED), "COUNT_ALLOCS" => Ok(BuildFlag::COUNT_ALLOCS), other => Ok(BuildFlag::Other(other.to_owned())), @@ -1194,10 +1194,9 @@ impl FromStr for BuildFlag { pub struct BuildFlags(pub HashSet); impl BuildFlags { - const ALL: [BuildFlag; 5] = [ + const ALL: [BuildFlag; 4] = [ BuildFlag::Py_DEBUG, BuildFlag::Py_REF_DEBUG, - BuildFlag::Py_TRACE_REFS, BuildFlag::Py_GIL_DISABLED, BuildFlag::COUNT_ALLOCS, ]; From 285c3f7b95a3e11b077f8c9bf1f601fddbae926e Mon Sep 17 00:00:00 2001 From: Cheukting Date: Tue, 17 Feb 2026 18:38:30 +0000 Subject: [PATCH 2/4] Add news fragment for `Py_TRACE_REFS` deprecation and removal. --- newsfragments/5824.changed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/5824.changed.md diff --git a/newsfragments/5824.changed.md b/newsfragments/5824.changed.md new file mode 100644 index 00000000000..3bcfc0afda2 --- /dev/null +++ b/newsfragments/5824.changed.md @@ -0,0 +1 @@ +Deprecate and remove `Py_TRACE_REFS` support (unsupported from Python 3.13). \ No newline at end of file From 4f7bb3b4ab960a624b24255fb61cea56032ce22a Mon Sep 17 00:00:00 2001 From: Cheuk Ting Ho Date: Tue, 17 Feb 2026 22:44:55 +0200 Subject: [PATCH 3/4] Update pyo3-build-config/src/impl_.rs Co-authored-by: David Hewitt --- pyo3-build-config/src/impl_.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyo3-build-config/src/impl_.rs b/pyo3-build-config/src/impl_.rs index 0a28fa80ca7..a2e04c00df2 100644 --- a/pyo3-build-config/src/impl_.rs +++ b/pyo3-build-config/src/impl_.rs @@ -1147,7 +1147,7 @@ pub fn cross_compiling_from_cargo_env() -> Result> { pub enum BuildFlag { Py_DEBUG, Py_REF_DEBUG, - #[deprecated = "Not supported since Python 3.13"] + #[deprecated(since = "0.29.0", note = "no longer supported by PyO3")] Py_TRACE_REFS, Py_GIL_DISABLED, COUNT_ALLOCS, From 65061a5952691711f8d990c48256a1986e007e70 Mon Sep 17 00:00:00 2001 From: Cheukting Date: Tue, 17 Feb 2026 21:52:15 +0000 Subject: [PATCH 4/4] Remove final traces of `Py_TRACE_REFS` support. --- pyo3-ffi/src/modsupport.rs | 27 +-------------------------- pyo3-ffi/src/object.rs | 8 -------- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/pyo3-ffi/src/modsupport.rs b/pyo3-ffi/src/modsupport.rs index b6186ddc8bc..e3dd1f2ee7c 100644 --- a/pyo3-ffi/src/modsupport.rs +++ b/pyo3-ffi/src/modsupport.rs @@ -83,7 +83,7 @@ pub const PYTHON_API_VERSION: i32 = 1013; pub const PYTHON_ABI_VERSION: i32 = 3; extern "C" { - #[cfg(not(py_sys_config = "Py_TRACE_REFS"))] + #[cfg_attr(PyPy, link_name = "PyPyModule_Create2")] pub fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; } @@ -101,10 +101,7 @@ pub unsafe fn PyModule_Create(module: *mut PyModuleDef) -> *mut PyObject { } extern "C" { - #[cfg(py_sys_config = "Py_TRACE_REFS")] - fn PyModule_Create2TraceRefs(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject; - #[cfg(not(py_sys_config = "Py_TRACE_REFS"))] #[cfg_attr(PyPy, link_name = "PyPyModule_FromDefAndSpec2")] pub fn PyModule_FromDefAndSpec2( def: *mut PyModuleDef, @@ -112,28 +109,6 @@ extern "C" { module_api_version: c_int, ) -> *mut PyObject; - #[cfg(py_sys_config = "Py_TRACE_REFS")] - fn PyModule_FromDefAndSpec2TraceRefs( - def: *mut PyModuleDef, - spec: *mut PyObject, - module_api_version: c_int, - ) -> *mut PyObject; -} - -#[cfg(py_sys_config = "Py_TRACE_REFS")] -#[inline] -pub unsafe fn PyModule_Create2(module: *mut PyModuleDef, apiver: c_int) -> *mut PyObject { - PyModule_Create2TraceRefs(module, apiver) -} - -#[cfg(py_sys_config = "Py_TRACE_REFS")] -#[inline] -pub unsafe fn PyModule_FromDefAndSpec2( - def: *mut PyModuleDef, - spec: *mut PyObject, - module_api_version: c_int, -) -> *mut PyObject { - PyModule_FromDefAndSpec2TraceRefs(def, spec, module_api_version) } #[inline] diff --git a/pyo3-ffi/src/object.rs b/pyo3-ffi/src/object.rs index ddeabb9be3f..a6fc6d39ff6 100644 --- a/pyo3-ffi/src/object.rs +++ b/pyo3-ffi/src/object.rs @@ -96,10 +96,6 @@ const _PyObject_MIN_ALIGNMENT: usize = 4; #[cfg_attr(all(Py_3_15, Py_GIL_DISABLED), repr(C, align(4)))] #[derive(Debug)] pub struct PyObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] - pub _ob_next: *mut PyObject, - #[cfg(py_sys_config = "Py_TRACE_REFS")] - pub _ob_prev: *mut PyObject, #[cfg(Py_GIL_DISABLED)] pub ob_tid: libc::uintptr_t, #[cfg(all(Py_GIL_DISABLED, not(Py_3_14)))] @@ -128,10 +124,6 @@ const _: () = assert!(std::mem::align_of::() >= _PyObject_MIN_ALIGNMEN reason = "contains atomic refcount on free-threaded builds" )] pub const PyObject_HEAD_INIT: PyObject = PyObject { - #[cfg(py_sys_config = "Py_TRACE_REFS")] - _ob_next: std::ptr::null_mut(), - #[cfg(py_sys_config = "Py_TRACE_REFS")] - _ob_prev: std::ptr::null_mut(), #[cfg(Py_GIL_DISABLED)] ob_tid: 0, #[cfg(all(Py_GIL_DISABLED, Py_3_15))]