Skip to content

Commit 6009cc8

Browse files
authored
Merge pull request #1695 from messense/wrap-function-prelude
Add `wrap_pyfunction` macro to prelude
2 parents 3bf283d + b5b9a48 commit 6009cc8

29 files changed

+12
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3333
- Add `#[pyo3(text_signature = "...")]` syntax for setting text signature. [#1658](https://github.com/PyO3/pyo3/pull/1658)
3434
- Add support for setting and retrieving exception cause. [#1679](https://github.com/PyO3/pyo3/pull/1679)
3535
- Add FFI definitions from `cpython/pystate.h`.[#1687](https://github.com/PyO3/pyo3/pull/1687/)
36+
- Add `wrap_pyfunction` macro to prelude. [#1695](https://github.com/PyO3/pyo3/pull/1695)
3637

3738
### Changed
3839

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ features = ["extension-module"]
5858

5959
```rust
6060
use pyo3::prelude::*;
61-
use pyo3::wrap_pyfunction;
6261

6362
/// Formats the sum of two numbers as string.
6463
#[pyfunction]

examples/pyo3-benchmarks/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use pyo3::prelude::*;
22
use pyo3::types::{PyDict, PyTuple};
3-
use pyo3::wrap_pyfunction;
43

54
#[pyfunction]
65
fn none() {}

examples/pyo3-pytests/src/datetime.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use pyo3::types::{
33
PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, PyTime, PyTimeAccess, PyTuple,
44
PyTzInfo,
55
};
6-
use pyo3::wrap_pyfunction;
76

87
#[pyfunction]
98
fn make_date(py: Python, year: i32, month: u8, day: u8) -> PyResult<&PyDate> {

examples/pyo3-pytests/src/misc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use pyo3::prelude::*;
2-
use pyo3::wrap_pyfunction;
32

43
#[pyfunction]
54
fn issue_219() {

examples/pyo3-pytests/src/othermod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! The code below just tries to use the most important code generation paths
44
55
use pyo3::prelude::*;
6-
use pyo3::wrap_pyfunction;
76

87
#[pyclass]
98
pub struct ModClass {

examples/pyo3-pytests/src/path.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use pyo3::prelude::*;
2-
use pyo3::wrap_pyfunction;
32
use std::path::{Path, PathBuf};
43

54
#[pyfunction]

examples/word-count/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// https://github.com/tildeio/helix-website/blob/master/crates/word_count/src/lib.rs
33

44
use pyo3::prelude::*;
5-
use pyo3::wrap_pyfunction;
65
use rayon::prelude::*;
76

87
/// Searches for the word, parallelized by rayon

guide/src/ecosystem/logging.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ It's also possible to tweak its configuration (mostly to tune its performance).
2121
```rust
2222
use log::info;
2323
use pyo3::prelude::*;
24-
use pyo3::wrap_pyfunction;
2524

2625
#[pyfunction]
2726
fn log_something() {

guide/src/function.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ One way is annotating a function with `#[pyfunction]` and then adding it to the
66

77
```rust
88
use pyo3::prelude::*;
9-
use pyo3::wrap_pyfunction;
109

1110
#[pyfunction]
1211
fn double(x: usize) -> usize {
@@ -54,7 +53,7 @@ fn rust2py(py: Python, m: &PyModule) -> PyResult<()> {
5453
Ok(format!("{}", a + b))
5554
}
5655

57-
m.add_function(pyo3::wrap_pyfunction!(sum_as_string, m)?)?;
56+
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
5857

5958
Ok(())
6059
}
@@ -72,7 +71,6 @@ The `#[pyo3]` attribute can be used to modify properties of the generated Python
7271

7372
```rust
7473
use pyo3::prelude::*;
75-
use pyo3::wrap_pyfunction;
7674

7775
#[pyfunction]
7876
#[pyo3(name = "no_args")]
@@ -97,7 +95,6 @@ The `#[pyfunction]` attribute supports specifying details of argument parsing. T
9795

9896
```rust
9997
use pyo3::prelude::*;
100-
use pyo3::wrap_pyfunction;
10198
use pyo3::types::PyDict;
10299

103100
#[pyfunction(kwds="**")]
@@ -258,7 +255,6 @@ in Python code.
258255
It is possible to access the module of a `#[pyfunction]` in the function body by using `#[pyo3(pass_module)]` option:
259256

260257
```rust
261-
use pyo3::wrap_pyfunction;
262258
use pyo3::prelude::*;
263259

264260
#[pyfunction]

guide/src/module.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ dicts or other modules:
6666

6767
```rust
6868
use pyo3::prelude::*;
69-
use pyo3::{wrap_pyfunction, wrap_pymodule};
69+
use pyo3::wrap_pymodule;
7070
use pyo3::types::IntoPyDict;
7171

7272
#[pyfunction]

guide/src/trait_bounds.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ It is also required to make the struct public.
461461

462462
```rust
463463
use pyo3::prelude::*;
464-
use pyo3::wrap_pyfunction;
465464
use pyo3::types::PyAny;
466465

467466
pub trait Model {

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@
157157
//!
158158
//! ```rust
159159
//! use pyo3::prelude::*;
160-
//! use pyo3::wrap_pyfunction;
161160
//!
162161
//! /// Formats the sum of two numbers as string.
163162
//! #[pyfunction]

src/num_bigint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
//! ```rust
3535
//! use num_bigint::BigInt;
3636
//! use pyo3::prelude::*;
37-
//! use pyo3::wrap_pyfunction;
3837
//!
3938
//! #[pyfunction]
4039
//! fn add_one(n: BigInt) -> BigInt {

src/num_complex.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
//! use nalgebra::base::{dimension::Const, storage::Storage, Matrix};
3232
//! use num_complex::Complex;
3333
//! use pyo3::prelude::*;
34-
//! use pyo3::wrap_pyfunction;
3534
//!
3635
//! type T = Complex<f64>;
3736
//!

src/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ pub use crate::python::Python;
1919
pub use crate::{FromPyObject, IntoPy, IntoPyPointer, PyTryFrom, PyTryInto, ToPyObject};
2020
// PyModule is only part of the prelude because we need it for the pymodule function
2121
pub use crate::types::{PyAny, PyModule};
22+
pub use crate::wrap_pyfunction;
2223
#[cfg(feature = "macros")]
2324
pub use {crate::proc_macro::*, pyo3_macros::FromPyObject};

src/python.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'p> Python<'p> {
189189
///
190190
/// # Examples
191191
/// ```
192-
/// # use pyo3::prelude::*; use pyo3::types::IntoPyDict; use pyo3::wrap_pyfunction;
192+
/// # use pyo3::prelude::*; use pyo3::types::IntoPyDict;
193193
/// use pyo3::exceptions::PyRuntimeError;
194194
/// use std::sync::Arc;
195195
/// use std::thread;

src/types/module.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ impl PyModule {
346346
///
347347
/// ```rust
348348
/// use pyo3::prelude::*;
349-
/// use pyo3::wrap_pyfunction;
350349
///
351350
/// #[pyfunction]
352351
/// fn say_hello() {

tests/test_bytes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use pyo3::prelude::*;
22
use pyo3::types::PyBytes;
3-
use pyo3::wrap_pyfunction;
43

54
mod common;
65

tests/test_exceptions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use pyo3::prelude::*;
2-
use pyo3::{exceptions, py_run, wrap_pyfunction, PyErr, PyResult};
2+
use pyo3::{exceptions, py_run, PyErr, PyResult};
33
use std::error::Error;
44
use std::fmt;
55
#[cfg(not(target_os = "windows"))]

tests/test_macros.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Ensure that pyo3 macros can be used inside macro_rules!
22
33
use pyo3::prelude::*;
4-
use pyo3::wrap_pyfunction;
54

65
#[macro_use]
76
mod common;

tests/test_module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use pyo3::prelude::*;
22

3+
use pyo3::py_run;
34
use pyo3::types::{IntoPyDict, PyDict, PyTuple};
4-
use pyo3::{py_run, wrap_pyfunction};
55
mod common;
66

77
#[pyclass]

tests/test_pyfunction.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use pyo3::prelude::*;
44
use pyo3::types::PyCFunction;
55
#[cfg(not(Py_LIMITED_API))]
66
use pyo3::types::{PyDateTime, PyFunction};
7-
use pyo3::wrap_pyfunction;
87

98
mod common;
109

tests/test_string.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use pyo3::prelude::*;
2-
use pyo3::wrap_pyfunction;
32

43
mod common;
54

tests/test_text_signature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use pyo3::prelude::*;
2-
use pyo3::{types::PyType, wrap_pyfunction, wrap_pymodule, PyCell};
2+
use pyo3::{types::PyType, wrap_pymodule, PyCell};
33

44
mod common;
55

tests/test_various.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use pyo3::prelude::*;
22
use pyo3::types::{PyDict, PyTuple};
3-
use pyo3::{py_run, wrap_pyfunction, PyCell};
3+
use pyo3::{py_run, PyCell};
44

55
use std::fmt;
66

tests/test_wrap_pyfunction_deduction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use pyo3::{prelude::*, types::PyCFunction, wrap_pyfunction};
1+
use pyo3::{prelude::*, types::PyCFunction};
22

33
#[pyfunction]
44
fn f() {}

tests/ui/invalid_result_conversion.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! *doesn't* implement `From<MyError> for PyErr` won't be automatically
33
//! converted when using `#[pyfunction]`.
44
use pyo3::prelude::*;
5-
use pyo3::wrap_pyfunction;
65

76
use std::fmt;
87

tests/ui/invalid_result_conversion.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error[E0277]: the trait bound `Result<(), MyError>: IntoPyCallbackOutput<_>` is not satisfied
2-
--> $DIR/invalid_result_conversion.rs:22:1
2+
--> $DIR/invalid_result_conversion.rs:21:1
33
|
4-
22 | #[pyfunction]
4+
21 | #[pyfunction]
55
| ^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `Result<(), MyError>`
66
|
77
::: $WORKSPACE/src/callback.rs

0 commit comments

Comments
 (0)