diff --git a/src/callback.rs b/src/callback.rs index 77928406313..e29f07e0979 100644 --- a/src/callback.rs +++ b/src/callback.rs @@ -244,23 +244,6 @@ where let unwind_safe_py = AssertUnwindSafe(pool.python()); let panic_result = panic::catch_unwind(move || -> PyResult<_> { let py = *unwind_safe_py; - #[cfg(all(PyPy, not(Py_3_8)))] - { - const PYPY_GOOD_VERSION: [u8; 3] = [7, 3, 8]; - let version = py - .import("sys")? - .getattr("implementation")? - .getattr("version")?; - if version.compare(crate::types::PyTuple::new(py, &PYPY_GOOD_VERSION))? - == std::cmp::Ordering::Less - { - let warn = py.import("warnings")?.getattr("warn")?; - warn.call1(( - "PyPy 3.7 versions older than 7.3.8 are known to have binary \ - compatibility issues which may cause segfaults. Please upgrade.", - ))?; - } - } body(py) }); diff --git a/src/derive_utils.rs b/src/derive_utils.rs index 6d79b2c4dad..cfb9a816627 100644 --- a/src/derive_utils.rs +++ b/src/derive_utils.rs @@ -319,6 +319,24 @@ impl ModuleDef { py: Python, initializer: impl Fn(Python, &PyModule) -> PyResult<()>, ) -> PyResult<*mut ffi::PyObject> { + #[cfg(all(PyPy, not(Py_3_8)))] + { + const PYPY_GOOD_VERSION: [u8; 3] = [7, 3, 8]; + let version = py + .import("sys")? + .getattr("implementation")? + .getattr("version")?; + if version.compare(crate::types::PyTuple::new(py, &PYPY_GOOD_VERSION))? + == std::cmp::Ordering::Less + { + let warn = py.import("warnings")?.getattr("warn")?; + warn.call1(( + "PyPy 3.7 versions older than 7.3.8 are known to have binary \ + compatibility issues which may cause segfaults. Please upgrade.", + ))?; + } + } + let module = unsafe { py.from_owned_ptr_or_err::(ffi::PyModule_Create(self.0.get()))? }; initializer(py, module)?;