From d9258212cb0cab7deb897415c138f9d7f24dad96 Mon Sep 17 00:00:00 2001 From: Icxolu <10486322+Icxolu@users.noreply.github.com> Date: Fri, 11 Oct 2024 10:08:52 +0200 Subject: [PATCH] move `callback` module into `impl_` (#4613) --- pyo3-macros-backend/src/method.rs | 4 ++-- pyo3-macros-backend/src/pymethod.rs | 14 +++++++------- src/impl_.rs | 1 + src/{ => impl_}/callback.rs | 0 src/impl_/pyclass.rs | 2 +- src/impl_/pymethods.rs | 2 +- src/impl_/trampoline.rs | 2 +- src/lib.rs | 2 -- src/pycell.rs | 2 +- src/pyclass_init.rs | 2 +- src/types/function.rs | 8 ++++---- src/types/module.rs | 2 +- 12 files changed, 20 insertions(+), 21 deletions(-) rename src/{ => impl_}/callback.rs (100%) diff --git a/pyo3-macros-backend/src/method.rs b/pyo3-macros-backend/src/method.rs index 633083dea95..50f70d8440a 100644 --- a/pyo3-macros-backend/src/method.rs +++ b/pyo3-macros-backend/src/method.rs @@ -312,7 +312,7 @@ impl ExtractErrorMode { ExtractErrorMode::NotImplemented => quote! { match #extract { ::std::result::Result::Ok(value) => value, - ::std::result::Result::Err(_) => { return #pyo3_path::callback::convert(py, py.NotImplemented()); }, + ::std::result::Result::Err(_) => { return #pyo3_path::impl_::callback::convert(py, py.NotImplemented()); }, } }, } @@ -836,7 +836,7 @@ impl<'a> FnSpec<'a> { _args: *mut #pyo3_path::ffi::PyObject, _kwargs: *mut #pyo3_path::ffi::PyObject ) -> #pyo3_path::PyResult<*mut #pyo3_path::ffi::PyObject> { - use #pyo3_path::callback::IntoPyCallbackOutput; + use #pyo3_path::impl_::callback::IntoPyCallbackOutput; #deprecation let _slf_ref = &_slf; let function = #rust_name; // Shadow the function name to avoid #3017 diff --git a/pyo3-macros-backend/src/pymethod.rs b/pyo3-macros-backend/src/pymethod.rs index e7e50145e04..ec8b264884d 100644 --- a/pyo3-macros-backend/src/pymethod.rs +++ b/pyo3-macros-backend/src/pymethod.rs @@ -684,7 +684,7 @@ pub fn impl_py_setter_def( #init_holders #extract let result = #setter_impl; - #pyo3_path::callback::convert(py, result) + #pyo3_path::impl_::callback::convert(py, result) } }; @@ -813,7 +813,7 @@ pub fn impl_py_getter_def( let wrapper_ident = format_ident!("__pymethod_get_{}__", spec.name); let call = impl_call_getter(cls, spec, self_type, &mut holders, ctx)?; let body = quote! { - #pyo3_path::callback::convert(py, #call) + #pyo3_path::impl_::callback::convert(py, #call) }; let init_holders = holders.init_holders(ctx); @@ -916,7 +916,7 @@ pub const __REPR__: SlotDef = SlotDef::new("Py_tp_repr", "reprfunc"); pub const __HASH__: SlotDef = SlotDef::new("Py_tp_hash", "hashfunc") .ret_ty(Ty::PyHashT) .return_conversion(TokenGenerator( - |Ctx { pyo3_path, .. }: &Ctx| quote! { #pyo3_path::callback::HashCallbackOutput }, + |Ctx { pyo3_path, .. }: &Ctx| quote! { #pyo3_path::impl_::callback::HashCallbackOutput }, )); pub const __RICHCMP__: SlotDef = SlotDef::new("Py_tp_richcompare", "richcmpfunc") .extract_error_mode(ExtractErrorMode::NotImplemented) @@ -1169,8 +1169,8 @@ impl ReturnMode { ReturnMode::Conversion(conversion) => { let conversion = TokenGeneratorCtx(*conversion, ctx); quote! { - let _result: #pyo3_path::PyResult<#conversion> = #pyo3_path::callback::convert(py, #call); - #pyo3_path::callback::convert(py, _result) + let _result: #pyo3_path::PyResult<#conversion> = #pyo3_path::impl_::callback::convert(py, #call); + #pyo3_path::impl_::callback::convert(py, _result) } } ReturnMode::SpecializedConversion(traits, tag) => { @@ -1183,7 +1183,7 @@ impl ReturnMode { } } ReturnMode::ReturnSelf => quote! { - let _result: #pyo3_path::PyResult<()> = #pyo3_path::callback::convert(py, #call); + let _result: #pyo3_path::PyResult<()> = #pyo3_path::impl_::callback::convert(py, #call); _result?; #pyo3_path::ffi::Py_XINCREF(_raw_slf); ::std::result::Result::Ok(_raw_slf) @@ -1356,7 +1356,7 @@ fn generate_method_body( } else { quote! { let result = #call; - #pyo3_path::callback::convert(py, result) + #pyo3_path::impl_::callback::convert(py, result) } }) } diff --git a/src/impl_.rs b/src/impl_.rs index 5bfeda39f65..d6b918c6820 100644 --- a/src/impl_.rs +++ b/src/impl_.rs @@ -6,6 +6,7 @@ //! APIs may may change at any time without documentation in the CHANGELOG and without //! breaking semver guarantees. +pub mod callback; #[cfg(feature = "experimental-async")] pub mod coroutine; pub mod exceptions; diff --git a/src/callback.rs b/src/impl_/callback.rs similarity index 100% rename from src/callback.rs rename to src/impl_/callback.rs diff --git a/src/impl_/pyclass.rs b/src/impl_/pyclass.rs index 4e3ed140a76..01b824c69ab 100644 --- a/src/impl_/pyclass.rs +++ b/src/impl_/pyclass.rs @@ -446,7 +446,7 @@ macro_rules! define_pyclass_setattr_slot { value, |py, _slf, attr, value| { use ::std::option::Option::*; - use $crate::callback::IntoPyCallbackOutput; + use $crate::impl_::callback::IntoPyCallbackOutput; use $crate::impl_::pyclass::*; let collector = PyClassImplCollector::<$cls>::new(); if let Some(value) = ::std::ptr::NonNull::new(value) { diff --git a/src/impl_/pymethods.rs b/src/impl_/pymethods.rs index c4d09a8fdd3..1c6e136deac 100644 --- a/src/impl_/pymethods.rs +++ b/src/impl_/pymethods.rs @@ -1,6 +1,6 @@ -use crate::callback::IntoPyCallbackOutput; use crate::exceptions::PyStopAsyncIteration; use crate::gil::LockGIL; +use crate::impl_::callback::IntoPyCallbackOutput; use crate::impl_::panic::PanicTrap; use crate::impl_::pycell::{PyClassObject, PyClassObjectLayout}; use crate::pycell::impl_::PyClassBorrowChecker as _; diff --git a/src/impl_/trampoline.rs b/src/impl_/trampoline.rs index 2892095e736..7ffad8abdcd 100644 --- a/src/impl_/trampoline.rs +++ b/src/impl_/trampoline.rs @@ -11,7 +11,7 @@ use std::{ use crate::gil::GILGuard; use crate::{ - callback::PyCallbackOutput, ffi, ffi_ptr_ext::FfiPtrExt, impl_::panic::PanicTrap, + ffi, ffi_ptr_ext::FfiPtrExt, impl_::callback::PyCallbackOutput, impl_::panic::PanicTrap, impl_::pymethods::IPowModulo, panic::PanicException, types::PyModule, Py, PyResult, Python, }; diff --git a/src/lib.rs b/src/lib.rs index 239b001b8ac..7de32ca264f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -414,8 +414,6 @@ mod internal_tricks; mod internal; pub mod buffer; -#[doc(hidden)] -pub mod callback; pub mod conversion; mod conversions; #[cfg(feature = "experimental-async")] diff --git a/src/pycell.rs b/src/pycell.rs index a330e4962dc..1451e5499ce 100644 --- a/src/pycell.rs +++ b/src/pycell.rs @@ -68,7 +68,7 @@ //! .downcast::<_pyo3::PyCell>()?; //! let mut _ref = _cell.try_borrow_mut()?; //! let _slf: &mut Number = &mut *_ref; -//! _pyo3::callback::convert(py, Number::increment(_slf)) +//! _pyo3::impl_::callback::convert(py, Number::increment(_slf)) //! }) //! } //! ``` diff --git a/src/pyclass_init.rs b/src/pyclass_init.rs index 77976321adf..c164dd50315 100644 --- a/src/pyclass_init.rs +++ b/src/pyclass_init.rs @@ -1,6 +1,6 @@ //! Contains initialization utilities for `#[pyclass]`. -use crate::callback::IntoPyCallbackOutput; use crate::ffi_ptr_ext::FfiPtrExt; +use crate::impl_::callback::IntoPyCallbackOutput; use crate::impl_::pyclass::{PyClassBaseType, PyClassDict, PyClassThreadChecker, PyClassWeakRef}; use crate::internal::get_slot::TP_ALLOC; use crate::types::{PyAnyMethods, PyType}; diff --git a/src/types/function.rs b/src/types/function.rs index fdc4bc9e7bf..f443403aa67 100644 --- a/src/types/function.rs +++ b/src/types/function.rs @@ -104,7 +104,7 @@ impl PyCFunction { ) -> PyResult> where F: Fn(&Bound<'_, PyTuple>, Option<&Bound<'_, PyDict>>) -> R + Send + 'static, - for<'p> R: crate::callback::IntoPyCallbackOutput<'p, *mut ffi::PyObject>, + for<'p> R: crate::impl_::callback::IntoPyCallbackOutput<'p, *mut ffi::PyObject>, { let name = name.unwrap_or(ffi::c_str!("pyo3-closure")); let doc = doc.unwrap_or(ffi::c_str!("")); @@ -142,7 +142,7 @@ impl PyCFunction { ) -> PyResult> where F: Fn(&Bound<'_, PyTuple>, Option<&Bound<'_, PyDict>>) -> R + Send + 'static, - for<'p> R: crate::callback::IntoPyCallbackOutput<'p, *mut ffi::PyObject>, + for<'p> R: crate::impl_::callback::IntoPyCallbackOutput<'p, *mut ffi::PyObject>, { Self::new_closure(py, name, doc, closure) } @@ -185,7 +185,7 @@ unsafe extern "C" fn run_closure( ) -> *mut ffi::PyObject where F: Fn(&Bound<'_, PyTuple>, Option<&Bound<'_, PyDict>>) -> R + Send + 'static, - for<'py> R: crate::callback::IntoPyCallbackOutput<'py, *mut ffi::PyObject>, + for<'py> R: crate::impl_::callback::IntoPyCallbackOutput<'py, *mut ffi::PyObject>, { use crate::types::any::PyAnyMethods; @@ -202,7 +202,7 @@ where .as_ref() .map(|b| b.downcast_unchecked::()); let result = (boxed_fn.closure)(args, kwargs); - crate::callback::convert(py, result) + crate::impl_::callback::convert(py, result) }, ) } diff --git a/src/types/module.rs b/src/types/module.rs index a0398c42be4..3822ed86714 100644 --- a/src/types/module.rs +++ b/src/types/module.rs @@ -1,7 +1,7 @@ -use crate::callback::IntoPyCallbackOutput; use crate::conversion::IntoPyObject; use crate::err::{PyErr, PyResult}; use crate::ffi_ptr_ext::FfiPtrExt; +use crate::impl_::callback::IntoPyCallbackOutput; use crate::py_result_ext::PyResultExt; use crate::pyclass::PyClass; use crate::types::{