Skip to content

Commit

Permalink
move callback module into impl_ (#4613)
Browse files Browse the repository at this point in the history
  • Loading branch information
Icxolu authored Oct 11, 2024
1 parent 50a254d commit d925821
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions pyo3-macros-backend/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()); },
}
},
}
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pyo3-macros-backend/src/pymethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) => {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
})
}
Expand Down
1 change: 1 addition & 0 deletions src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/impl_/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/impl_/pymethods.rs
Original file line number Diff line number Diff line change
@@ -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 _;
Expand Down
2 changes: 1 addition & 1 deletion src/impl_/trampoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion src/pycell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
//! .downcast::<_pyo3::PyCell<Number>>()?;
//! 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))
//! })
//! }
//! ```
Expand Down
2 changes: 1 addition & 1 deletion src/pyclass_init.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
8 changes: 4 additions & 4 deletions src/types/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl PyCFunction {
) -> PyResult<Bound<'py, Self>>
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!(""));
Expand Down Expand Up @@ -142,7 +142,7 @@ impl PyCFunction {
) -> PyResult<Bound<'py, Self>>
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)
}
Expand Down Expand Up @@ -185,7 +185,7 @@ unsafe extern "C" fn run_closure<F, R>(
) -> *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;

Expand All @@ -202,7 +202,7 @@ where
.as_ref()
.map(|b| b.downcast_unchecked::<PyDict>());
let result = (boxed_fn.closure)(args, kwargs);
crate::callback::convert(py, result)
crate::impl_::callback::convert(py, result)
},
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/module.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down

0 comments on commit d925821

Please sign in to comment.