Skip to content

Commit

Permalink
fix deprecations in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Icxolu committed Mar 7, 2024
1 parent 0d3e76f commit d48e1ee
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion guide/src/exception.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use pyo3::exceptions::PyException;
pyo3::create_exception!(mymodule, CustomError, PyException);

#[pymodule]
fn mymodule(py: Python<'_>, m: &PyModule) -> PyResult<()> {
fn mymodule(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
// ... other elements added to module ...
m.add("CustomError", py.get_type_bound::<CustomError>())?;

Expand Down
2 changes: 1 addition & 1 deletion guide/src/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ fn my_module(_py: Python<'_>, m: &PyModule) -> PyResult<()> {

To fix it, make the private submodule visible, e.g. with `pub` or `pub(crate)`.

```rust
```rust,ignore
mod foo {
use pyo3::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion pytests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod sequence;
pub mod subclassing;

#[pymodule]
fn pyo3_pytests(py: Python<'_>, m: &PyModule) -> PyResult<()> {
fn pyo3_pytests(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pymodule!(awaitable::awaitable))?;
#[cfg(not(Py_LIMITED_API))]
m.add_wrapped(wrap_pymodule!(buf_and_str::buf_and_str))?;
Expand Down
2 changes: 2 additions & 0 deletions src/tests/hygiene/pymodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ fn do_something(x: i32) -> crate::PyResult<i32> {
::std::result::Result::Ok(x)
}

#[allow(deprecated)]
#[crate::pymodule]
#[pyo3(crate = "crate")]
fn foo(_py: crate::Python<'_>, _m: &crate::types::PyModule) -> crate::PyResult<()> {
::std::result::Result::Ok(())
}

#[allow(deprecated)]
#[crate::pymodule]
#[pyo3(crate = "crate")]
fn my_module(_py: crate::Python<'_>, m: &crate::types::PyModule) -> crate::PyResult<()> {
Expand Down
8 changes: 4 additions & 4 deletions src/types/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,11 @@ impl PyModule {
/// use pyo3::prelude::*;
///
/// #[pymodule]
/// fn my_module(py: Python<'_>, module: &PyModule) -> PyResult<()> {
/// fn my_module(py: Python<'_>, module: &Bound<'_, PyModule>) -> PyResult<()> {
/// let submodule = PyModule::new_bound(py, "submodule")?;
/// submodule.add("super_useful_constant", "important")?;
///
/// module.add_submodule(submodule.as_gil_ref())?;
/// module.add_submodule(&submodule)?;
/// Ok(())
/// }
/// ```
Expand Down Expand Up @@ -530,11 +530,11 @@ pub trait PyModuleMethods<'py>: crate::sealed::Sealed {
/// use pyo3::prelude::*;
///
/// #[pymodule]
/// fn my_module(py: Python<'_>, module: &PyModule) -> PyResult<()> {
/// fn my_module(py: Python<'_>, module: &Bound<'_, PyModule>) -> PyResult<()> {
/// let submodule = PyModule::new_bound(py, "submodule")?;
/// submodule.add("super_useful_constant", "important")?;
///
/// module.add_submodule(submodule.as_gil_ref())?;
/// module.add_submodule(&submodule)?;
/// Ok(())
/// }
/// ```
Expand Down
2 changes: 1 addition & 1 deletion tests/test_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn test_module_with_functions() {

/// This module uses a legacy two-argument module function.
#[pymodule]
fn module_with_explicit_py_arg(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
fn module_with_explicit_py_arg(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(double, m)?)?;
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions tests/test_no_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fn basic_function(py: pyo3::Python<'_>, x: Option<pyo3::PyObject>) -> pyo3::PyOb
x.unwrap_or_else(|| py.None())
}

#[allow(deprecated)]
#[pyo3::pymodule]
fn basic_module(_py: pyo3::Python<'_>, m: &pyo3::types::PyModule) -> pyo3::PyResult<()> {
#[pyfn(m)]
Expand Down

0 comments on commit d48e1ee

Please sign in to comment.