Merge pull request #1695 from messense/wrap-function-prelude
Add `wrap_pyfunction` macro to prelude
This commit is contained in:
commit
6009cc82cb
|
@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||||
- Add `#[pyo3(text_signature = "...")]` syntax for setting text signature. [#1658](https://github.com/PyO3/pyo3/pull/1658)
|
- Add `#[pyo3(text_signature = "...")]` syntax for setting text signature. [#1658](https://github.com/PyO3/pyo3/pull/1658)
|
||||||
- Add support for setting and retrieving exception cause. [#1679](https://github.com/PyO3/pyo3/pull/1679)
|
- Add support for setting and retrieving exception cause. [#1679](https://github.com/PyO3/pyo3/pull/1679)
|
||||||
- Add FFI definitions from `cpython/pystate.h`.[#1687](https://github.com/PyO3/pyo3/pull/1687/)
|
- Add FFI definitions from `cpython/pystate.h`.[#1687](https://github.com/PyO3/pyo3/pull/1687/)
|
||||||
|
- Add `wrap_pyfunction` macro to prelude. [#1695](https://github.com/PyO3/pyo3/pull/1695)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,6 @@ features = ["extension-module"]
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
/// Formats the sum of two numbers as string.
|
/// Formats the sum of two numbers as string.
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::types::{PyDict, PyTuple};
|
use pyo3::types::{PyDict, PyTuple};
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn none() {}
|
fn none() {}
|
||||||
|
|
|
@ -3,7 +3,6 @@ use pyo3::types::{
|
||||||
PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, PyTime, PyTimeAccess, PyTuple,
|
PyDate, PyDateAccess, PyDateTime, PyDelta, PyDeltaAccess, PyTime, PyTimeAccess, PyTuple,
|
||||||
PyTzInfo,
|
PyTzInfo,
|
||||||
};
|
};
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn make_date(py: Python, year: i32, month: u8, day: u8) -> PyResult<&PyDate> {
|
fn make_date(py: Python, year: i32, month: u8, day: u8) -> PyResult<&PyDate> {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn issue_219() {
|
fn issue_219() {
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
//! The code below just tries to use the most important code generation paths
|
//! The code below just tries to use the most important code generation paths
|
||||||
|
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
pub struct ModClass {
|
pub struct ModClass {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// https://github.com/tildeio/helix-website/blob/master/crates/word_count/src/lib.rs
|
// https://github.com/tildeio/helix-website/blob/master/crates/word_count/src/lib.rs
|
||||||
|
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
/// Searches for the word, parallelized by rayon
|
/// Searches for the word, parallelized by rayon
|
||||||
|
|
|
@ -21,7 +21,6 @@ It's also possible to tweak its configuration (mostly to tune its performance).
|
||||||
```rust
|
```rust
|
||||||
use log::info;
|
use log::info;
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn log_something() {
|
fn log_something() {
|
||||||
|
|
|
@ -6,7 +6,6 @@ One way is annotating a function with `#[pyfunction]` and then adding it to the
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn double(x: usize) -> usize {
|
fn double(x: usize) -> usize {
|
||||||
|
@ -54,7 +53,7 @@ fn rust2py(py: Python, m: &PyModule) -> PyResult<()> {
|
||||||
Ok(format!("{}", a + b))
|
Ok(format!("{}", a + b))
|
||||||
}
|
}
|
||||||
|
|
||||||
m.add_function(pyo3::wrap_pyfunction!(sum_as_string, m)?)?;
|
m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -72,7 +71,6 @@ The `#[pyo3]` attribute can be used to modify properties of the generated Python
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
#[pyo3(name = "no_args")]
|
#[pyo3(name = "no_args")]
|
||||||
|
@ -97,7 +95,6 @@ The `#[pyfunction]` attribute supports specifying details of argument parsing. T
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
use pyo3::types::PyDict;
|
use pyo3::types::PyDict;
|
||||||
|
|
||||||
#[pyfunction(kwds="**")]
|
#[pyfunction(kwds="**")]
|
||||||
|
@ -258,7 +255,6 @@ in Python code.
|
||||||
It is possible to access the module of a `#[pyfunction]` in the function body by using `#[pyo3(pass_module)]` option:
|
It is possible to access the module of a `#[pyfunction]` in the function body by using `#[pyo3(pass_module)]` option:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
|
|
|
@ -66,7 +66,7 @@ dicts or other modules:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::{wrap_pyfunction, wrap_pymodule};
|
use pyo3::wrap_pymodule;
|
||||||
use pyo3::types::IntoPyDict;
|
use pyo3::types::IntoPyDict;
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
|
|
|
@ -461,7 +461,6 @@ It is also required to make the struct public.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
use pyo3::types::PyAny;
|
use pyo3::types::PyAny;
|
||||||
|
|
||||||
pub trait Model {
|
pub trait Model {
|
||||||
|
|
|
@ -157,7 +157,6 @@
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use pyo3::prelude::*;
|
//! use pyo3::prelude::*;
|
||||||
//! use pyo3::wrap_pyfunction;
|
|
||||||
//!
|
//!
|
||||||
//! /// Formats the sum of two numbers as string.
|
//! /// Formats the sum of two numbers as string.
|
||||||
//! #[pyfunction]
|
//! #[pyfunction]
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! use num_bigint::BigInt;
|
//! use num_bigint::BigInt;
|
||||||
//! use pyo3::prelude::*;
|
//! use pyo3::prelude::*;
|
||||||
//! use pyo3::wrap_pyfunction;
|
|
||||||
//!
|
//!
|
||||||
//! #[pyfunction]
|
//! #[pyfunction]
|
||||||
//! fn add_one(n: BigInt) -> BigInt {
|
//! fn add_one(n: BigInt) -> BigInt {
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
//! use nalgebra::base::{dimension::Const, storage::Storage, Matrix};
|
//! use nalgebra::base::{dimension::Const, storage::Storage, Matrix};
|
||||||
//! use num_complex::Complex;
|
//! use num_complex::Complex;
|
||||||
//! use pyo3::prelude::*;
|
//! use pyo3::prelude::*;
|
||||||
//! use pyo3::wrap_pyfunction;
|
|
||||||
//!
|
//!
|
||||||
//! type T = Complex<f64>;
|
//! type T = Complex<f64>;
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -19,5 +19,6 @@ pub use crate::python::Python;
|
||||||
pub use crate::{FromPyObject, IntoPy, IntoPyPointer, PyTryFrom, PyTryInto, ToPyObject};
|
pub use crate::{FromPyObject, IntoPy, IntoPyPointer, PyTryFrom, PyTryInto, ToPyObject};
|
||||||
// PyModule is only part of the prelude because we need it for the pymodule function
|
// PyModule is only part of the prelude because we need it for the pymodule function
|
||||||
pub use crate::types::{PyAny, PyModule};
|
pub use crate::types::{PyAny, PyModule};
|
||||||
|
pub use crate::wrap_pyfunction;
|
||||||
#[cfg(feature = "macros")]
|
#[cfg(feature = "macros")]
|
||||||
pub use {crate::proc_macro::*, pyo3_macros::FromPyObject};
|
pub use {crate::proc_macro::*, pyo3_macros::FromPyObject};
|
||||||
|
|
|
@ -189,7 +189,7 @@ impl<'p> Python<'p> {
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// # use pyo3::prelude::*; use pyo3::types::IntoPyDict; use pyo3::wrap_pyfunction;
|
/// # use pyo3::prelude::*; use pyo3::types::IntoPyDict;
|
||||||
/// use pyo3::exceptions::PyRuntimeError;
|
/// use pyo3::exceptions::PyRuntimeError;
|
||||||
/// use std::sync::Arc;
|
/// use std::sync::Arc;
|
||||||
/// use std::thread;
|
/// use std::thread;
|
||||||
|
|
|
@ -346,7 +346,6 @@ impl PyModule {
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use pyo3::prelude::*;
|
/// use pyo3::prelude::*;
|
||||||
/// use pyo3::wrap_pyfunction;
|
|
||||||
///
|
///
|
||||||
/// #[pyfunction]
|
/// #[pyfunction]
|
||||||
/// fn say_hello() {
|
/// fn say_hello() {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::types::PyBytes;
|
use pyo3::types::PyBytes;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::{exceptions, py_run, wrap_pyfunction, PyErr, PyResult};
|
use pyo3::{exceptions, py_run, PyErr, PyResult};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//! Ensure that pyo3 macros can be used inside macro_rules!
|
//! Ensure that pyo3 macros can be used inside macro_rules!
|
||||||
|
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod common;
|
mod common;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
|
|
||||||
|
use pyo3::py_run;
|
||||||
use pyo3::types::{IntoPyDict, PyDict, PyTuple};
|
use pyo3::types::{IntoPyDict, PyDict, PyTuple};
|
||||||
use pyo3::{py_run, wrap_pyfunction};
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
|
|
|
@ -4,7 +4,6 @@ use pyo3::prelude::*;
|
||||||
use pyo3::types::PyCFunction;
|
use pyo3::types::PyCFunction;
|
||||||
#[cfg(not(Py_LIMITED_API))]
|
#[cfg(not(Py_LIMITED_API))]
|
||||||
use pyo3::types::{PyDateTime, PyFunction};
|
use pyo3::types::{PyDateTime, PyFunction};
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::{types::PyType, wrap_pyfunction, wrap_pymodule, PyCell};
|
use pyo3::{types::PyType, wrap_pymodule, PyCell};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::types::{PyDict, PyTuple};
|
use pyo3::types::{PyDict, PyTuple};
|
||||||
use pyo3::{py_run, wrap_pyfunction, PyCell};
|
use pyo3::{py_run, PyCell};
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use pyo3::{prelude::*, types::PyCFunction, wrap_pyfunction};
|
use pyo3::{prelude::*, types::PyCFunction};
|
||||||
|
|
||||||
#[pyfunction]
|
#[pyfunction]
|
||||||
fn f() {}
|
fn f() {}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
//! *doesn't* implement `From<MyError> for PyErr` won't be automatically
|
//! *doesn't* implement `From<MyError> for PyErr` won't be automatically
|
||||||
//! converted when using `#[pyfunction]`.
|
//! converted when using `#[pyfunction]`.
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::wrap_pyfunction;
|
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
error[E0277]: the trait bound `Result<(), MyError>: IntoPyCallbackOutput<_>` is not satisfied
|
error[E0277]: the trait bound `Result<(), MyError>: IntoPyCallbackOutput<_>` is not satisfied
|
||||||
--> $DIR/invalid_result_conversion.rs:22:1
|
--> $DIR/invalid_result_conversion.rs:21:1
|
||||||
|
|
|
|
||||||
22 | #[pyfunction]
|
21 | #[pyfunction]
|
||||||
| ^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `Result<(), MyError>`
|
| ^^^^^^^^^^^^^ the trait `IntoPyCallbackOutput<_>` is not implemented for `Result<(), MyError>`
|
||||||
|
|
|
|
||||||
::: $WORKSPACE/src/callback.rs
|
::: $WORKSPACE/src/callback.rs
|
||||||
|
|
Loading…
Reference in a new issue