Skip to content

Commit

Permalink
remove some methods impl details from public API (#4441)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt authored Aug 15, 2024
1 parent ffeb901 commit e14aab5
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 33 deletions.
1 change: 1 addition & 0 deletions newsfragments/4441.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate `IPowModulo`, `PyClassAttributeDef`, `PyGetterDef`, `PyMethodDef`, `PyMethodDefType`, and `PySetterDef` from PyO3's public API.
4 changes: 2 additions & 2 deletions pyo3-macros-backend/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,8 +1541,8 @@ pub fn gen_complex_enum_variant_attr(

let method_def = quote! {
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
#pyo3_path::class::PyMethodDefType::ClassAttribute({
#pyo3_path::class::PyClassAttributeDef::new(
#pyo3_path::impl_::pymethods::PyMethodDefType::ClassAttribute({
#pyo3_path::impl_::pymethods::PyClassAttributeDef::new(
#python_name,
#cls_type::#wrapper_ident
)
Expand Down
4 changes: 2 additions & 2 deletions pyo3-macros-backend/src/pyimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ pub fn gen_py_const(cls: &syn::Type, spec: &ConstSpec, ctx: &Ctx) -> MethodAndMe

let method_def = quote! {
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
#pyo3_path::class::PyMethodDefType::ClassAttribute({
#pyo3_path::class::PyClassAttributeDef::new(
#pyo3_path::impl_::pymethods::PyMethodDefType::ClassAttribute({
#pyo3_path::impl_::pymethods::PyClassAttributeDef::new(
#python_name,
#cls::#wrapper_ident
)
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 @@ -330,7 +330,7 @@ pub fn impl_py_method_def(
let methoddef = spec.get_methoddef(quote! { #cls::#wrapper_ident }, doc, ctx);
let method_def = quote! {
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
#pyo3_path::class::PyMethodDefType::#methoddef_type(#methoddef #add_flags)
#pyo3_path::impl_::pymethods::PyMethodDefType::#methoddef_type(#methoddef #add_flags)
)
};
Ok(MethodAndMethodDef {
Expand Down Expand Up @@ -510,8 +510,8 @@ fn impl_py_class_attribute(

let method_def = quote! {
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
#pyo3_path::class::PyMethodDefType::ClassAttribute({
#pyo3_path::class::PyClassAttributeDef::new(
#pyo3_path::impl_::pymethods::PyMethodDefType::ClassAttribute({
#pyo3_path::impl_::pymethods::PyClassAttributeDef::new(
#python_name,
#cls::#wrapper_ident
)
Expand Down Expand Up @@ -691,8 +691,8 @@ pub fn impl_py_setter_def(
let method_def = quote! {
#cfg_attrs
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
#pyo3_path::class::PyMethodDefType::Setter(
#pyo3_path::class::PySetterDef::new(
#pyo3_path::impl_::pymethods::PyMethodDefType::Setter(
#pyo3_path::impl_::pymethods::PySetterDef::new(
#python_name,
#cls::#wrapper_ident,
#doc
Expand Down Expand Up @@ -826,8 +826,8 @@ pub fn impl_py_getter_def(
let method_def = quote! {
#cfg_attrs
#pyo3_path::impl_::pyclass::MaybeRuntimePyMethodDef::Static(
#pyo3_path::class::PyMethodDefType::Getter(
#pyo3_path::class::PyGetterDef::new(
#pyo3_path::impl_::pymethods::PyMethodDefType::Getter(
#pyo3_path::impl_::pymethods::PyGetterDef::new(
#python_name,
#cls::#wrapper_ident,
#doc
Expand Down
16 changes: 9 additions & 7 deletions src/impl_/pyclass.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::{
exceptions::{PyAttributeError, PyNotImplementedError, PyRuntimeError, PyValueError},
ffi,
impl_::freelist::FreeList,
impl_::pycell::{GetBorrowChecker, PyClassMutability, PyClassObjectLayout},
impl_::{
freelist::FreeList,
pycell::{GetBorrowChecker, PyClassMutability, PyClassObjectLayout},
pymethods::{PyGetterDef, PyMethodDefType},
},
pyclass_init::PyObjectInit,
types::{any::PyAnyMethods, PyBool},
Borrowed, IntoPy, Py, PyAny, PyClass, PyErr, PyMethodDefType, PyResult, PyTypeInfo, Python,
ToPyObject,
Borrowed, IntoPy, Py, PyAny, PyClass, PyErr, PyResult, PyTypeInfo, Python, ToPyObject,
};
use std::{
borrow::Cow,
Expand Down Expand Up @@ -1249,7 +1251,7 @@ impl<
doc: doc.as_ptr(),
})
} else {
PyMethodDefType::Getter(crate::PyGetterDef {
PyMethodDefType::Getter(PyGetterDef {
name,
meth: pyo3_get_value_topyobject::<ClassT, Py<U>, Offset>,
doc,
Expand All @@ -1263,7 +1265,7 @@ impl<ClassT: PyClass, FieldT: ToPyObject, Offset: OffsetCalculator<ClassT, Field
PyClassGetterGenerator<ClassT, FieldT, Offset, false, true>
{
pub const fn generate(&self, name: &'static CStr, doc: &'static CStr) -> PyMethodDefType {
PyMethodDefType::Getter(crate::PyGetterDef {
PyMethodDefType::Getter(PyGetterDef {
name,
meth: pyo3_get_value_topyobject::<ClassT, FieldT, Offset>,
doc,
Expand Down Expand Up @@ -1292,7 +1294,7 @@ impl<ClassT: PyClass, FieldT, Offset: OffsetCalculator<ClassT, FieldT>>
where
FieldT: PyO3GetField,
{
PyMethodDefType::Getter(crate::PyGetterDef {
PyMethodDefType::Getter(PyGetterDef {
name,
meth: pyo3_get_value::<ClassT, FieldT, Offset>,
doc,
Expand Down
3 changes: 2 additions & 1 deletion src/impl_/pyclass/lazy_type_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ use crate::{
exceptions::PyRuntimeError,
ffi,
impl_::pyclass::MaybeRuntimePyMethodDef,
impl_::pymethods::PyMethodDefType,
pyclass::{create_type_object, PyClassTypeObject},
sync::{GILOnceCell, GILProtected},
types::PyType,
Bound, PyClass, PyErr, PyMethodDefType, PyObject, PyResult, Python,
Bound, PyClass, PyErr, PyObject, PyResult, Python,
};

use super::PyClassItemsIter;
Expand Down
3 changes: 2 additions & 1 deletion src/impl_/pymodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ use std::sync::atomic::{AtomicI64, Ordering};
use crate::exceptions::PyImportError;
use crate::{
ffi,
impl_::pymethods::PyMethodDef,
sync::GILOnceCell,
types::{PyCFunction, PyModule, PyModuleMethods},
Bound, Py, PyClass, PyMethodDef, PyResult, PyTypeInfo, Python,
Bound, Py, PyClass, PyResult, PyTypeInfo, Python,
};

/// `Sync` wrapper of `ffi::PyModuleDef`.
Expand Down
2 changes: 1 addition & 1 deletion src/impl_/trampoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
use crate::gil::GILGuard;
use crate::{
callback::PyCallbackOutput, ffi, ffi_ptr_ext::FfiPtrExt, impl_::panic::PanicTrap,
methods::IPowModulo, panic::PanicException, types::PyModule, Py, PyResult, Python,
impl_::pymethods::IPowModulo, panic::PanicException, types::PyModule, Py, PyResult, Python,
};

#[inline]
Expand Down
25 changes: 15 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,24 @@ pub(crate) mod sealed;
pub mod class {
pub use self::gc::{PyTraverseError, PyVisit};

#[doc(hidden)]
pub use self::methods::{
PyClassAttributeDef, PyGetterDef, PyMethodDef, PyMethodDefType, PyMethodType, PySetterDef,
};
pub use self::methods::*;

#[doc(hidden)]
pub mod methods {
// frozen with the contents of the `impl_::pymethods` module in 0.20,
// this should probably all be replaced with deprecated type aliases and removed.
pub use crate::impl_::pymethods::{
IPowModulo, PyClassAttributeDef, PyGetterDef, PyMethodDef, PyMethodDefType,
PyMethodType, PySetterDef,
};
#[deprecated(since = "0.23.0", note = "PyO3 implementation detail")]
pub type IPowModulo = crate::impl_::pymethods::IPowModulo;
#[deprecated(since = "0.23.0", note = "PyO3 implementation detail")]
pub type PyClassAttributeDef = crate::impl_::pymethods::PyClassAttributeDef;
#[deprecated(since = "0.23.0", note = "PyO3 implementation detail")]
pub type PyGetterDef = crate::impl_::pymethods::PyGetterDef;
#[deprecated(since = "0.23.0", note = "PyO3 implementation detail")]
pub type PyMethodDef = crate::impl_::pymethods::PyMethodDef;
#[deprecated(since = "0.23.0", note = "PyO3 implementation detail")]
pub type PyMethodDefType = crate::impl_::pymethods::PyMethodDefType;
#[deprecated(since = "0.23.0", note = "PyO3 implementation detail")]
pub type PyMethodType = crate::impl_::pymethods::PyMethodType;
#[deprecated(since = "0.23.0", note = "PyO3 implementation detail")]
pub type PySetterDef = crate::impl_::pymethods::PySetterDef;
}

/// Old module which contained some implementation details of the `#[pyproto]` module.
Expand Down
4 changes: 2 additions & 2 deletions src/pyclass/create_type_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use crate::{
assign_sequence_item_from_mapping, get_sequence_item_from_mapping, tp_dealloc,
tp_dealloc_with_gc, MaybeRuntimePyMethodDef, PyClassItemsIter,
},
pymethods::{Getter, Setter},
pymethods::{Getter, PyGetterDef, PyMethodDefType, PySetterDef, Setter},
trampoline::trampoline,
},
internal_tricks::ptr_from_ref,
types::{typeobject::PyTypeMethods, PyType},
Py, PyClass, PyGetterDef, PyMethodDefType, PyResult, PySetterDef, PyTypeInfo, Python,
Py, PyClass, PyResult, PyTypeInfo, Python,
};
use std::{
collections::HashMap,
Expand Down

0 comments on commit e14aab5

Please sign in to comment.