Fix coding style in docstrings.
This commit is contained in:
parent
08423557d4
commit
717e09be13
|
@ -68,7 +68,7 @@
|
|||
//!
|
||||
//! #[pyfunction]
|
||||
//! fn calculate_statistics(data: Vec<i32>) -> IndexMap<&'static str, f32> {
|
||||
//! indexmap!{
|
||||
//! indexmap! {
|
||||
//! "median" => median(&data),
|
||||
//! "mean" => mean(&data),
|
||||
//! "mode" => mode(&data),
|
||||
|
|
|
@ -210,7 +210,7 @@ mod array_impls {
|
|||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
let needs_drop = self.elements.get_mut(self.start..).unwrap();
|
||||
for item in needs_drop{
|
||||
for item in needs_drop {
|
||||
ManuallyDrop::drop(item);
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ mod array_impls {
|
|||
|
||||
let slf = ManuallyDrop::new(self);
|
||||
|
||||
let mut guard = ArrayGuard{
|
||||
let mut guard = ArrayGuard {
|
||||
// the transmute size check is _very_ dumb around generics
|
||||
elements: transmute_copy(&slf),
|
||||
start: 0
|
||||
|
|
|
@ -594,7 +594,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn from_py_string_type_error() {
|
||||
Python::with_gil(|py|{
|
||||
Python::with_gil(|py| {
|
||||
let obj = ("123").to_object(py);
|
||||
let err = obj.extract::<$t>(py).unwrap_err();
|
||||
assert!(err.is_instance_of::<exceptions::PyTypeError>(py));
|
||||
|
@ -603,7 +603,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn from_py_float_type_error() {
|
||||
Python::with_gil(|py|{
|
||||
Python::with_gil(|py| {
|
||||
let obj = (12.3).to_object(py);
|
||||
let err = obj.extract::<$t>(py).unwrap_err();
|
||||
assert!(err.is_instance_of::<exceptions::PyTypeError>(py));});
|
||||
|
@ -611,7 +611,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn to_py_object_and_back() {
|
||||
Python::with_gil(|py|{
|
||||
Python::with_gil(|py| {
|
||||
let val = 123 as $t;
|
||||
let obj = val.to_object(py);
|
||||
assert_eq!(obj.extract::<$t>(py).unwrap(), val as $t);});
|
||||
|
@ -689,7 +689,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn from_py_string_type_error() {
|
||||
Python::with_gil(|py|{
|
||||
Python::with_gil(|py| {
|
||||
let obj = ("123").to_object(py);
|
||||
let err = obj.extract::<$t>(py).unwrap_err();
|
||||
assert!(err.is_instance_of::<exceptions::PyTypeError>(py));
|
||||
|
@ -698,7 +698,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn from_py_float_type_error() {
|
||||
Python::with_gil(|py|{
|
||||
Python::with_gil(|py| {
|
||||
let obj = (12.3).to_object(py);
|
||||
let err = obj.extract::<$t>(py).unwrap_err();
|
||||
assert!(err.is_instance_of::<exceptions::PyTypeError>(py));});
|
||||
|
@ -706,7 +706,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn to_py_object_and_back() {
|
||||
Python::with_gil(|py|{
|
||||
Python::with_gil(|py| {
|
||||
let val = <$t>::new(123).unwrap();
|
||||
let obj = val.to_object(py);
|
||||
assert_eq!(obj.extract::<$t>(py).unwrap(), val);});
|
||||
|
|
|
@ -154,7 +154,7 @@ macro_rules! import_exception {
|
|||
/// create_exception!(my_module, MyError, PyException, "Some description.");
|
||||
///
|
||||
/// #[pyfunction]
|
||||
/// fn raise_myerror() -> PyResult<()>{
|
||||
/// fn raise_myerror() -> PyResult<()> {
|
||||
/// let err = MyError::new_err("Some error happened.");
|
||||
/// Err(err)
|
||||
/// }
|
||||
|
@ -636,7 +636,7 @@ impl PyUnicodeDecodeError {
|
|||
/// use pyo3::exceptions::PyUnicodeDecodeError;
|
||||
///
|
||||
/// # fn main() -> PyResult<()> {
|
||||
/// Python::with_gil(|py|{
|
||||
/// Python::with_gil(|py| {
|
||||
/// let invalid_utf8 = b"fo\xd8o";
|
||||
/// let err = std::str::from_utf8(invalid_utf8).expect_err("should be invalid utf8");
|
||||
/// let decode_err = PyUnicodeDecodeError::new_utf8(py, invalid_utf8, err)?;
|
||||
|
|
10
src/gil.rs
10
src/gil.rs
|
@ -56,7 +56,7 @@ pub(crate) fn gil_is_acquired() -> bool {
|
|||
/// ```rust
|
||||
/// use pyo3::prelude::*;
|
||||
///
|
||||
/// # fn main() -> PyResult<()>{
|
||||
/// # fn main() -> PyResult<()> {
|
||||
/// pyo3::prepare_freethreaded_python();
|
||||
/// Python::with_gil(|py| py.run("print('Hello World')", None, None))
|
||||
/// # }
|
||||
|
@ -101,10 +101,10 @@ pub fn prepare_freethreaded_python() {
|
|||
/// ```rust
|
||||
/// unsafe {
|
||||
/// pyo3::with_embedded_python_interpreter(|py| {
|
||||
/// if let Err(e) = py.run("print('Hello World')", None, None){
|
||||
/// // We must make sure to not return a `PyErr`!
|
||||
/// e.print(py);
|
||||
/// }
|
||||
/// if let Err(e) = py.run("print('Hello World')", None, None) {
|
||||
/// // We must make sure to not return a `PyErr`!
|
||||
/// e.print(py);
|
||||
/// }
|
||||
/// });
|
||||
/// }
|
||||
/// ```
|
||||
|
|
|
@ -110,7 +110,7 @@
|
|||
//! impl !Ungil for ffi::PyObject {}
|
||||
//!
|
||||
//! // `Py` wraps it in a safe api, so this is OK
|
||||
//! unsafe impl <T> Ungil for Py<T> {}
|
||||
//! unsafe impl<T> Ungil for Py<T> {}
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
|
@ -796,7 +796,7 @@ impl<'py> Python<'py> {
|
|||
/// # #![allow(dead_code)] // this example is quite impractical to test
|
||||
/// use pyo3::prelude::*;
|
||||
///
|
||||
/// # fn main(){
|
||||
/// # fn main() {
|
||||
/// #[pyfunction]
|
||||
/// fn loop_forever(py: Python<'_>) -> PyResult<()> {
|
||||
/// loop {
|
||||
|
|
|
@ -123,20 +123,20 @@ impl<T> GILOnceCell<T> {
|
|||
///
|
||||
/// #[pyfunction]
|
||||
/// fn create_dict(py: Python<'_>) -> PyResult<&PyDict> {
|
||||
/// let dict = PyDict::new(py);
|
||||
/// // 👇 A new `PyString` is created
|
||||
/// // for every call of this function.
|
||||
/// dict.set_item("foo", 42)?;
|
||||
/// Ok(dict)
|
||||
/// let dict = PyDict::new(py);
|
||||
/// // 👇 A new `PyString` is created
|
||||
/// // for every call of this function.
|
||||
/// dict.set_item("foo", 42)?;
|
||||
/// Ok(dict)
|
||||
/// }
|
||||
///
|
||||
/// #[pyfunction]
|
||||
/// fn create_dict_faster(py: Python<'_>) -> PyResult<&PyDict> {
|
||||
/// let dict = PyDict::new(py);
|
||||
/// // 👇 A `PyString` is created once and reused
|
||||
/// // for the lifetime of the program.
|
||||
/// dict.set_item(intern!(py, "foo"), 42)?;
|
||||
/// Ok(dict)
|
||||
/// let dict = PyDict::new(py);
|
||||
/// // 👇 A `PyString` is created once and reused
|
||||
/// // for the lifetime of the program.
|
||||
/// dict.set_item(intern!(py, "foo"), 42)?;
|
||||
/// Ok(dict)
|
||||
/// }
|
||||
/// #
|
||||
/// # Python::with_gil(|py| {
|
||||
|
|
|
@ -105,7 +105,7 @@
|
|||
//! // `PyRefMut` before borrowing again.
|
||||
//! drop(guard);
|
||||
//!
|
||||
//! let n_immutable : &Number = &n.as_ref(py).borrow();
|
||||
//! let n_immutable: &Number = &n.as_ref(py).borrow();
|
||||
//! assert_eq!(n_immutable.inner, 1);
|
||||
//!
|
||||
//! Ok(())
|
||||
|
@ -127,7 +127,7 @@
|
|||
//! std::mem::swap(&mut a.inner, &mut b.inner);
|
||||
//! }
|
||||
//! # fn main() {
|
||||
//! # Python::with_gil(|py|{
|
||||
//! # Python::with_gil(|py| {
|
||||
//! # let n = Py::new(py, Number{inner: 35}).unwrap();
|
||||
//! # let n2 = n.clone_ref(py);
|
||||
//! # assert!(n.is(&n2));
|
||||
|
@ -164,7 +164,7 @@
|
|||
//! }
|
||||
//! # fn main() {
|
||||
//! # // With duplicate numbers
|
||||
//! # Python::with_gil(|py|{
|
||||
//! # Python::with_gil(|py| {
|
||||
//! # let n = Py::new(py, Number{inner: 35}).unwrap();
|
||||
//! # let n2 = n.clone_ref(py);
|
||||
//! # assert!(n.is(&n2));
|
||||
|
@ -173,7 +173,7 @@
|
|||
//! # });
|
||||
//! #
|
||||
//! # // With two different numbers
|
||||
//! # Python::with_gil(|py|{
|
||||
//! # Python::with_gil(|py| {
|
||||
//! # let n = Py::new(py, Number{inner: 35}).unwrap();
|
||||
//! # let n2 = Py::new(py, Number{inner: 42}).unwrap();
|
||||
//! # assert!(!n.is(&n2));
|
||||
|
|
|
@ -475,7 +475,7 @@ impl CompareOp {
|
|||
///
|
||||
/// #[pyclass]
|
||||
/// struct Size {
|
||||
/// size: usize
|
||||
/// size: usize,
|
||||
/// }
|
||||
///
|
||||
/// #[pymethods]
|
||||
|
|
|
@ -16,28 +16,28 @@ use std::os::raw::{c_char, c_int, c_void};
|
|||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use std::ffi::CString;
|
||||
/// use pyo3::{prelude::*, types::PyCapsule};
|
||||
/// use pyo3::{prelude::*, types::PyCapsule};
|
||||
/// use std::ffi::CString;
|
||||
///
|
||||
/// #[repr(C)]
|
||||
/// struct Foo {
|
||||
/// pub val: u32,
|
||||
/// }
|
||||
/// #[repr(C)]
|
||||
/// struct Foo {
|
||||
/// pub val: u32,
|
||||
/// }
|
||||
///
|
||||
/// let r = Python::with_gil(|py| -> PyResult<()> {
|
||||
/// let foo = Foo { val: 123 };
|
||||
/// let name = CString::new("builtins.capsule").unwrap();
|
||||
/// let r = Python::with_gil(|py| -> PyResult<()> {
|
||||
/// let foo = Foo { val: 123 };
|
||||
/// let name = CString::new("builtins.capsule").unwrap();
|
||||
///
|
||||
/// let capsule = PyCapsule::new(py, foo, Some(name.clone()))?;
|
||||
/// let capsule = PyCapsule::new(py, foo, Some(name.clone()))?;
|
||||
///
|
||||
/// let module = PyModule::import(py, "builtins")?;
|
||||
/// module.add("capsule", capsule)?;
|
||||
/// let module = PyModule::import(py, "builtins")?;
|
||||
/// module.add("capsule", capsule)?;
|
||||
///
|
||||
/// let cap: &Foo = unsafe { PyCapsule::import(py, name.as_ref())? };
|
||||
/// assert_eq!(cap.val, 123);
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// assert!(r.is_ok());
|
||||
/// let cap: &Foo = unsafe { PyCapsule::import(py, name.as_ref())? };
|
||||
/// assert_eq!(cap.val, 123);
|
||||
/// Ok(())
|
||||
/// });
|
||||
/// assert!(r.is_ok());
|
||||
/// ```
|
||||
#[repr(transparent)]
|
||||
pub struct PyCapsule(PyAny);
|
||||
|
|
|
@ -111,7 +111,7 @@ mod tests {
|
|||
fn $func_name() {
|
||||
use assert_approx_eq::assert_approx_eq;
|
||||
|
||||
Python::with_gil(|py|{
|
||||
Python::with_gil(|py| {
|
||||
|
||||
let val = 123 as $t1;
|
||||
let obj = val.to_object(py);
|
||||
|
|
|
@ -32,8 +32,8 @@ impl PyModule {
|
|||
/// ``` rust
|
||||
/// use pyo3::prelude::*;
|
||||
///
|
||||
/// # fn main() -> PyResult<()>{
|
||||
/// Python::with_gil(|py| -> PyResult<()>{
|
||||
/// # fn main() -> PyResult<()> {
|
||||
/// Python::with_gil(|py| -> PyResult<()> {
|
||||
/// let module = PyModule::new(py, "my_module")?;
|
||||
///
|
||||
/// assert_eq!(module.name()?, "my_module");
|
||||
|
@ -52,7 +52,7 @@ impl PyModule {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # fn main(){
|
||||
/// # fn main() {
|
||||
/// use pyo3::prelude::*;
|
||||
///
|
||||
/// Python::with_gil(|py| {
|
||||
|
|
|
@ -18,7 +18,7 @@ impl PySuper {
|
|||
/// ```rust
|
||||
/// use pyo3::prelude::*;
|
||||
///
|
||||
///#[pyclass(subclass)]
|
||||
/// #[pyclass(subclass)]
|
||||
/// struct BaseClass {
|
||||
/// val1: usize,
|
||||
/// }
|
||||
|
|
Loading…
Reference in a new issue