Skip to content

Commit

Permalink
add deprecation ui test, revert closure variant due to test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Icxolu committed Mar 12, 2024
1 parent 0aef14b commit 88fe44f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ macro_rules! wrap_pyfunction {
($function:path) => {
&|py_or_module| {
use $function as wrapped_pyfunction;
let (py_or_module, e) = $crate::impl_::pyfunction::inspect_type(py_or_module);
e.is_python();
$crate::impl_::pyfunction::WrapPyFunctionArg::wrap_pyfunction(
py_or_module,
&wrapped_pyfunction::DEF,
Expand All @@ -146,7 +144,7 @@ macro_rules! wrap_pyfunction {
};
($function:path, $py_or_module:expr) => {{
use $function as wrapped_pyfunction;
let (py_or_module, e) = $crate::impl_::pyfunction::inspect_type($py_or_module);
let (py_or_module, e) = $crate::impl_::pymethods::inspect_type($py_or_module);
e.is_python();
$crate::impl_::pyfunction::WrapPyFunctionArg::wrap_pyfunction(
py_or_module,
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/deprecations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,19 @@ fn module_bound_by_value(m: Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(double, &m)?)?;
Ok(())
}

fn test_wrap_pyfunction(py: Python<'_>, m: &Bound<'_, PyModule>) {
// should lint
let _ = wrap_pyfunction!(double, py);

// should lint but currently does not
let _ = wrap_pyfunction!(double)(py);

// should not lint
let _ = wrap_pyfunction!(double, m);
let _ = wrap_pyfunction!(double)(m);
let _ = wrap_pyfunction!(double, m.as_gil_ref());
let _ = wrap_pyfunction!(double)(m.as_gil_ref());
let _ = wrap_pyfunction_bound!(double, py);
let _ = wrap_pyfunction_bound!(double)(py);
}
8 changes: 8 additions & 0 deletions tests/ui/deprecations.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ error: use of deprecated method `pyo3::methods::Extractor::<T>::extract_gil_ref`
|
53 | fn module_gil_ref_with_explicit_py_arg(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
| ^

error: use of deprecated method `pyo3::methods::Extractor::<pyo3::Python<'_>>::is_python`: use `wrap_pyfunction_bound!` instead
--> tests/ui/deprecations.rs:78:13
|
78 | let _ = wrap_pyfunction!(double, py);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `wrap_pyfunction` (in Nightly builds, run with -Z macro-backtrace for more info)

0 comments on commit 88fe44f

Please sign in to comment.