Skip to content

implement PyModuleMethods #3703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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