Skip to content

Commit

Permalink
seal PyAddToModule (PyO3#4606)
Browse files Browse the repository at this point in the history
* seal PyAddToModule

* adding change log

* fix changelog name
  • Loading branch information
Cheukting authored Oct 9, 2024
1 parent 4cbf6e0 commit 96da64b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions newsfragments/4606.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Seal `PyAddToModule` trait.
2 changes: 1 addition & 1 deletion src/impl_/pymodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl ModuleDef {
/// Trait to add an element (class, function...) to a module.
///
/// Currently only implemented for classes.
pub trait PyAddToModule {
pub trait PyAddToModule: crate::sealed::Sealed {
fn add_to_module(&'static self, module: &Bound<'_, PyModule>) -> PyResult<()>;
}

Expand Down
10 changes: 10 additions & 0 deletions src/sealed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use crate::types::{
};
use crate::{ffi, Bound, PyAny, PyResult};

use crate::impl_::{
pymethods::PyMethodDef,
pymodule::{AddClassToModule, AddTypeToModule, ModuleDef},
};

pub trait Sealed {}

// for FfiPtrExt
Expand Down Expand Up @@ -36,3 +41,8 @@ impl Sealed for Bound<'_, PyType> {}
impl Sealed for Bound<'_, PyWeakref> {}
impl Sealed for Bound<'_, PyWeakrefProxy> {}
impl Sealed for Bound<'_, PyWeakrefReference> {}

impl<T> Sealed for AddTypeToModule<T> {}
impl<T> Sealed for AddClassToModule<T> {}
impl Sealed for PyMethodDef {}
impl Sealed for ModuleDef {}

0 comments on commit 96da64b

Please sign in to comment.