Skip to content

Commit

Permalink
Merge pull request #3703 from davidhewitt/module2
Browse files Browse the repository at this point in the history
implement `PyModuleMethods`
  • Loading branch information
davidhewitt committed Dec 29, 2023
2 parents 6776b90 + e852a4b commit e1fcb4e
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 58 deletions.
1 change: 1 addition & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub use crate::types::float::PyFloatMethods;
pub use crate::types::frozenset::PyFrozenSetMethods;
pub use crate::types::list::PyListMethods;
pub use crate::types::mapping::PyMappingMethods;
pub use crate::types::module::PyModuleMethods;
pub use crate::types::sequence::PySequenceMethods;
pub use crate::types::set::PySetMethods;
pub use crate::types::string::PyStringMethods;
8 changes: 7 additions & 1 deletion src/py_result_ext.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{types::any::PyAnyMethods, Bound, PyAny, PyResult};
use crate::{types::any::PyAnyMethods, Bound, PyAny, PyResult, PyTypeCheck};

mod sealed {
use super::*;
Expand All @@ -11,10 +11,16 @@ mod sealed {
use sealed::Sealed;

pub(crate) trait PyResultExt<'py>: Sealed {
fn downcast_into<T: PyTypeCheck>(self) -> PyResult<Bound<'py, T>>;
unsafe fn downcast_into_unchecked<T>(self) -> PyResult<Bound<'py, T>>;
}

impl<'py> PyResultExt<'py> for PyResult<Bound<'py, PyAny>> {
#[inline]
fn downcast_into<T: PyTypeCheck>(self) -> PyResult<Bound<'py, T>> where {
self.and_then(|instance| instance.downcast_into().map_err(Into::into))
}

#[inline]
unsafe fn downcast_into_unchecked<T>(self) -> PyResult<Bound<'py, T>> {
self.map(|instance| instance.downcast_into_unchecked())
Expand Down
2 changes: 1 addition & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ mod iterator;
pub(crate) mod list;
pub(crate) mod mapping;
mod memoryview;
mod module;
pub(crate) mod module;
mod none;
mod notimplemented;
mod num;
Expand Down
Loading

0 comments on commit e1fcb4e

Please sign in to comment.