Skip to content

Commit e1fcb4e

Browse files
authored
Merge pull request #3703 from davidhewitt/module2
implement `PyModuleMethods`
2 parents 6776b90 + e852a4b commit e1fcb4e

File tree

5 files changed

+341
-58
lines changed

5 files changed

+341
-58
lines changed

src/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub use crate::types::float::PyFloatMethods;
3434
pub use crate::types::frozenset::PyFrozenSetMethods;
3535
pub use crate::types::list::PyListMethods;
3636
pub use crate::types::mapping::PyMappingMethods;
37+
pub use crate::types::module::PyModuleMethods;
3738
pub use crate::types::sequence::PySequenceMethods;
3839
pub use crate::types::set::PySetMethods;
3940
pub use crate::types::string::PyStringMethods;

src/py_result_ext.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{types::any::PyAnyMethods, Bound, PyAny, PyResult};
1+
use crate::{types::any::PyAnyMethods, Bound, PyAny, PyResult, PyTypeCheck};
22

33
mod sealed {
44
use super::*;
@@ -11,10 +11,16 @@ mod sealed {
1111
use sealed::Sealed;
1212

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

1718
impl<'py> PyResultExt<'py> for PyResult<Bound<'py, PyAny>> {
19+
#[inline]
20+
fn downcast_into<T: PyTypeCheck>(self) -> PyResult<Bound<'py, T>> where {
21+
self.and_then(|instance| instance.downcast_into().map_err(Into::into))
22+
}
23+
1824
#[inline]
1925
unsafe fn downcast_into_unchecked<T>(self) -> PyResult<Bound<'py, T>> {
2026
self.map(|instance| instance.downcast_into_unchecked())

src/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ mod iterator;
294294
pub(crate) mod list;
295295
pub(crate) mod mapping;
296296
mod memoryview;
297-
mod module;
297+
pub(crate) mod module;
298298
mod none;
299299
mod notimplemented;
300300
mod num;

0 commit comments

Comments
 (0)