Skip to content

Commit 5786143

Browse files
docs: use rumdl to make more sentences single-line (#5584)
* docs: use `rumdl` to make more sentences single-line * Update guide/src/class/call.md Co-authored-by: Lily <code@lilyf.org> --------- Co-authored-by: Lily <code@lilyf.org>
1 parent 1999aa9 commit 5786143

22 files changed

+83
-192
lines changed

guide/pyclass-parameters.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
| `unsendable` | Required if your struct is not [`Send`][params-3]. Rather than using `unsendable`, consider implementing your struct in a thread-safe way by e.g. substituting [`Rc`][params-4] with [`Arc`][params-5]. By using `unsendable`, your class will panic when accessed by another thread. Also note the Python's GC is multi-threaded and while unsendable classes will not be traversed on foreign threads to avoid UB, this can lead to memory leaks. |
2929
| `weakref` | Allows this class to be [weakly referenceable][params-6]. |
3030

31-
All of these parameters can either be passed directly on the `#[pyclass(...)]` annotation, or as one or
32-
more accompanying `#[pyo3(...)]` annotations, e.g.:
31+
All of these parameters can either be passed directly on the `#[pyclass(...)]` annotation, or as one or more accompanying `#[pyo3(...)]` annotations, e.g.:
3332

3433
```rust,ignore
3534
// Argument supplied directly to the `#[pyclass]` annotation.

guide/src/SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@
4343
---
4444

4545
[Appendix A: Migration guide](migration.md)
46+
4647
[Appendix B: Trait bounds](trait-bounds.md)
48+
4749
[Appendix C: Python typing hints](python-typing-hints.md)
50+
4851
[CHANGELOG](changelog.md)
4952

5053
---

guide/src/building-and-distribution.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,9 @@ As an advanced feature, you can build PyO3 wheel without calling Python interpre
255255
Also, if the build host Python interpreter is not found or is too old or otherwise unusable, PyO3 will still attempt to compile `abi3` extension modules after displaying a warning message.
256256
On Unix-like systems this works unconditionally; on Windows you must also set the `RUSTFLAGS` environment variable to contain `-L native=/path/to/python/libs` so that the linker can find `python3.lib`.
257257

258-
If the `python3.dll` import library is not available, an experimental `generate-import-lib` crate
259-
feature may be enabled, and the required library will be created and used by PyO3 automatically.
258+
If the `python3.dll` import library is not available, an experimental `generate-import-lib` crate feature may be enabled, and the required library will be created and used by PyO3 automatically.
260259

261-
*Note*: MSVC targets require LLVM binutils (`llvm-dlltool`) to be available in `PATH` for
262-
the automatic import library generation feature to work.
260+
*Note*: MSVC targets require LLVM binutils (`llvm-dlltool`) to be available in `PATH` for the automatic import library generation feature to work.
263261

264262
#### Missing features
265263

@@ -395,9 +393,7 @@ cargo build --target x86_64-pc-windows-gnu
395393

396394
Any of the `abi3-py3*` features can be enabled instead of setting `PYO3_CROSS_PYTHON_VERSION` in the above examples.
397395

398-
`PYO3_CROSS_LIB_DIR` can often be omitted when cross compiling extension modules for Unix and macOS targets,
399-
or when cross compiling extension modules for Windows and the experimental `generate-import-lib`
400-
crate feature is enabled.
396+
`PYO3_CROSS_LIB_DIR` can often be omitted when cross compiling extension modules for Unix and macOS targets, or when cross compiling extension modules for Windows and the experimental `generate-import-lib` crate feature is enabled.
401397

402398
The following resources may also be useful for cross-compiling:
403399

guide/src/class.md

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,11 @@ impl Nonzero {
184184
}
185185
```
186186

187-
If you want to return an existing object (for example, because your `new`
188-
method caches the values it returns), `new` can return `pyo3::Py<Self>`.
187+
If you want to return an existing object (for example, because your `new` method caches the values it returns), `new` can return `pyo3::Py<Self>`.
189188

190-
As you can see, the Rust method name is not important here; this way you can
191-
still, use `new()` for a Rust-level constructor.
189+
As you can see, the Rust method name is not important here; this way you can still, use `new()` for a Rust-level constructor.
192190

193-
If no method marked with `#[new]` is declared, object instances can only be
194-
created from Rust, but not from Python.
191+
If no method marked with `#[new]` is declared, object instances can only be created from Rust, but not from Python.
195192

196193
For arguments, see the [`Method arguments`](#method-arguments) section below.
197194

@@ -327,8 +324,7 @@ These parameters are covered in various sections of this guide.
327324

328325
### Return type
329326

330-
Generally, `#[new]` methods have to return `T: Into<PyClassInitializer<Self>>` or
331-
`PyResult<T> where T: Into<PyClassInitializer<Self>>`.
327+
Generally, `#[new]` methods have to return `T: Into<PyClassInitializer<Self>>` or `PyResult<T> where T: Into<PyClassInitializer<Self>>`.
332328

333329
For constructors that may fail, you should wrap the return type in a PyResult as well.
334330
Consult the table below to determine which type your constructor should return:
@@ -547,8 +543,7 @@ impl MyDict {
547543
# }
548544
```
549545

550-
Here, the `args` and `kwargs` allow creating instances of the subclass passing
551-
initial items, such as `MyDict(item_sequence)` or `MyDict(a=1, b=2)`.
546+
Here, the `args` and `kwargs` allow creating instances of the subclass passing initial items, such as `MyDict(item_sequence)` or `MyDict(a=1, b=2)`.
552547

553548
## Object properties
554549

@@ -695,11 +690,9 @@ impl MyClass {
695690

696691
Both `&self` and `&mut self` can be used, due to the use of [runtime borrow checking](#bound-and-interior-mutability).
697692

698-
The return type must be `PyResult<T>` or `T` for some `T` that implements `IntoPyObject`;
699-
the latter is allowed if the method cannot raise Python exceptions.
693+
The return type must be `PyResult<T>` or `T` for some `T` that implements `IntoPyObject`; the latter is allowed if the method cannot raise Python exceptions.
700694

701-
A `Python` parameter can be specified as part of method signature, in this case the `py` argument
702-
gets injected by the method wrapper, e.g.
695+
A `Python` parameter can be specified as part of method signature, in this case the `py` argument gets injected by the method wrapper, e.g.
703696

704697
```rust
705698
# use pyo3::prelude::*;
@@ -794,8 +787,7 @@ impl MyClass {
794787

795788
## Class attributes
796789

797-
To create a class attribute (also called [class variable][classattr]), a method without
798-
any arguments can be annotated with the `#[classattr]` attribute.
790+
To create a class attribute (also called [class variable][classattr]), a method without any arguments can be annotated with the `#[classattr]` attribute.
799791

800792
```rust,no_run
801793
# use pyo3::prelude::*;
@@ -820,8 +812,7 @@ class creation.
820812

821813
> Note: `#[classattr]` does not work with [`#[pyo3(warn(...))]`](./function.md#warn) attribute.
822814
823-
If the class attribute is defined with `const` code only, one can also annotate associated
824-
constants:
815+
If the class attribute is defined with `const` code only, one can also annotate associated constants:
825816

826817
```rust,no_run
827818
# use pyo3::prelude::*;
@@ -1054,8 +1045,7 @@ impl MyClass {
10541045
# }
10551046
```
10561047

1057-
Note that `text_signature` on `#[new]` is not compatible with compilation in
1058-
`abi3` mode until Python 3.10 or greater.
1048+
Note that `text_signature` on `#[new]` is not compatible with compilation in `abi3` mode until Python 3.10 or greater.
10591049

10601050
### Method receivers and lifetime elision
10611051

guide/src/class/call.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
Classes can be callable if they have a `#[pymethod]` named `__call__`.
44
This allows instances of a class to behave similar to functions.
55

6-
This method's signature must look like `__call__(<self>, ...) -> object` - here,
7-
any argument list can be defined as for normal pymethods
6+
This method's signature must look like `__call__(<self>, ...) -> object` - here, any argument list can be defined as for normal pymethods
87

98
## Example: Implementing a call counter
109

guide/src/class/object.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ mod my_module {
2525
}
2626
```
2727

28-
At this point Python code can import the module, access the class and create class instances - but
29-
nothing else.
28+
At this point Python code can import the module, access the class and create class instances - but nothing else.
3029

3130
```python
3231
from my_module import Number
@@ -99,8 +98,7 @@ It expands and is passed into the `format!` macro in the following ways:
9998
- `"{0}"` -> `"{}", self.0`
10099
- `"{x:?}"` -> `"{:?}", self.x`
101100

102-
*Note: Depending upon the format string you use, this may require implementation of the `Display` or `Debug` traits for the given Rust types.*
103-
*Note: the pyclass args `name` and `rename_all` are incompatible with the shorthand format string and will raise a compile time error.*
101+
*Note: Depending upon the format string you use, this may require implementation of the `Display` or `Debug` traits for the given Rust types.* *Note: the pyclass args `name` and `rename_all` are incompatible with the shorthand format string and will raise a compile time error.*
104102

105103
```rust,no_run
106104
# use pyo3::prelude::*;
@@ -239,8 +237,7 @@ impl Number {
239237
}
240238
```
241239
242-
If you obtain the result by comparing two Rust values, as in this example, you
243-
can take a shortcut using `CompareOp::matches`:
240+
If you obtain the result by comparing two Rust values, as in this example, you can take a shortcut using `CompareOp::matches`:
244241

245242
```rust,no_run
246243
use pyo3::class::basic::CompareOp;
@@ -259,8 +256,7 @@ impl Number {
259256
}
260257
```
261258

262-
It checks that the `std::cmp::Ordering` obtained from Rust's `Ord` matches
263-
the given `CompareOp`.
259+
It checks that the `std::cmp::Ordering` obtained from Rust's `Ord` matches the given `CompareOp`.
264260

265261
Alternatively, you can implement just equality using `__eq__`:
266262

guide/src/class/protocols.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ impl Container {
233233
# });
234234
```
235235

236-
For more details on Python's iteration protocols, check out [the "Iterator Types" section of the library
237-
documentation](https://docs.python.org/library/stdtypes.html#iterator-types).
236+
For more details on Python's iteration protocols, check out [the "Iterator Types" section of the library documentation](https://docs.python.org/library/stdtypes.html#iterator-types).
238237

239238
#### Returning a value from iteration
240239

@@ -363,11 +362,9 @@ This will help libraries such as `numpy` recognise the class as a sequence, howe
363362
364363
### Numeric types
365364
366-
Binary arithmetic operations (`+`, `-`, `*`, `@`, `/`, `//`, `%`, `divmod()`,
367-
`pow()` and `**`, `<<`, `>>`, `&`, `^`, and `|`) and their reflected versions:
365+
Binary arithmetic operations (`+`, `-`, `*`, `@`, `/`, `//`, `%`, `divmod()`, `pow()` and `**`, `<<`, `>>`, `&`, `^`, and `|`) and their reflected versions:
368366
369-
(If the `object` is not of the type specified in the signature, the generated code
370-
will automatically `return NotImplemented`.)
367+
(If the `object` is not of the type specified in the signature, the generated code will automatically `return NotImplemented`.)
371368
372369
- `__add__(<self>, object) -> object`
373370
- `__radd__(<self>, object) -> object`
@@ -398,8 +395,7 @@ will automatically `return NotImplemented`.)
398395
- `__pow__(<self>, object, object) -> object`
399396
- `__rpow__(<self>, object, object) -> object`
400397
401-
In-place assignment operations (`+=`, `-=`, `*=`, `@=`, `/=`, `//=`, `%=`,
402-
`**=`, `<<=`, `>>=`, `&=`, `^=`, `|=`):
398+
In-place assignment operations (`+=`, `-=`, `*=`, `@=`, `/=`, `//=`, `%=`, `**=`, `<<=`, `>>=`, `&=`, `^=`, `|=`):
403399
404400
- `__iadd__(<self>, object) -> ()`
405401
- `__isub__(<self>, object) -> ()`

guide/src/conversions/traits.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ let v: Vec<i32> = list.extract()?;
2020
# }
2121
```
2222

23-
This method is available for many Python object types, and can produce a wide
24-
variety of Rust types, which you can check out in the implementor list of
25-
[`FromPyObject`].
23+
This method is available for many Python object types, and can produce a wide variety of Rust types, which you can check out in the implementor list of [`FromPyObject`].
2624

2725
[`FromPyObject`] is also implemented for your own Rust types wrapped as Python objects (see [the chapter about classes](../class.md)).
2826
There, in order to both be able to operate on mutable references *and* satisfy Rust's rules of non-aliasing mutable references, you have to extract the PyO3 reference wrappers [`PyRef`] and [`PyRefMut`].
@@ -36,8 +34,7 @@ Derivation for empty enums, enum variants and structs is not supported.
3634

3735
### Deriving [`FromPyObject`] for structs
3836

39-
The derivation generates code that will attempt to access the attribute `my_string` on
40-
the Python object, i.e. `obj.getattr("my_string")`, and call `extract()` on the attribute.
37+
The derivation generates code that will attempt to access the attribute `my_string` on the Python object, i.e. `obj.getattr("my_string")`, and call `extract()` on the attribute.
4138

4239
```rust
4340
use pyo3::prelude::*;
@@ -447,8 +444,7 @@ enum RustyEnum {
447444
# }
448445
```
449446

450-
If the input is neither a string nor an integer, the error message will be:
451-
`"'<INPUT_TYPE>' cannot be cast as 'str | int'"`.
447+
If the input is neither a string nor an integer, the error message will be: `"'<INPUT_TYPE>' cannot be cast as 'str | int'"`.
452448

453449
### `#[derive(FromPyObject)]` Container Attributes
454450

@@ -560,16 +556,14 @@ All types in PyO3 implement this trait, as does a `#[pyclass]` which doesn't use
560556
This trait defines a single method, `into_pyobject()`, which returns a [`Result`] with `Ok` and `Err` types depending on the input value.
561557
For convenience, there is a companion [`IntoPyObjectExt`] trait which adds methods such as `into_py_any()` which converts the `Ok` and `Err` types to commonly used types (in the case of `into_py_any()`, `Py<PyAny>` and `PyErr` respectively).
562558

563-
Occasionally you may choose to implement this for custom types which are mapped to Python types
564-
*without* having a unique python type.
559+
Occasionally you may choose to implement this for custom types which are mapped to Python types *without* having a unique python type.
565560

566561
### derive macro
567562

568563
`IntoPyObject` can be implemented using our derive macro.
569564
Both `struct`s and `enum`s are supported.
570565

571-
`struct`s will turn into a `PyDict` using the field names as keys, tuple `struct`s will turn convert
572-
into `PyTuple` with the fields in declaration order.
566+
`struct`s will turn into a `PyDict` using the field names as keys, tuple `struct`s will turn convert into `PyTuple` with the fields in declaration order.
573567

574568
```rust,no_run
575569
# #![allow(dead_code)]
@@ -591,8 +585,7 @@ struct Struct {
591585
struct Tuple<'a, K: Hash + Eq, V>(&'a str, HashMap<K, V>);
592586
```
593587

594-
For structs with a single field (newtype pattern) the `#[pyo3(transparent)]` option can be used to
595-
forward the implementation to the inner type.
588+
For structs with a single field (newtype pattern) the `#[pyo3(transparent)]` option can be used to forward the implementation to the inner type.
596589

597590
```rust,no_run
598591
# #![allow(dead_code)]
@@ -660,8 +653,7 @@ All the same rules from above apply as well.
660653
661654
### manual implementation
662655
663-
If the derive macro is not suitable for your use case, `IntoPyObject` can be implemented manually as
664-
demonstrated below.
656+
If the derive macro is not suitable for your use case, `IntoPyObject` can be implemented manually as demonstrated below.
665657
666658
```rust,no_run
667659
# use pyo3::prelude::*;

guide/src/debugging.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,7 @@ Automated ways to discover thread safety issues can often be more fruitful than
358358
[ThreadSanitizer](https://clang.llvm.org/docs/ThreadSanitizer.html) is a thread safety checking runtime that can be used to detect data races triggered by thread safety bugs or incorrect use of thread-unsafe data structures.
359359
While it can only detect data races triggered by code at runtime, if it does detect something the reports often point to exactly where the problem is happening.
360360

361-
To use `ThreadSanitizer` with a library that depends on PyO3, you will need to
362-
install a nightly Rust toolchain, along with the `rust-src` component, since you
363-
will need to compile the Rust standard library:
361+
To use `ThreadSanitizer` with a library that depends on PyO3, you will need to install a nightly Rust toolchain, along with the `rust-src` component, since you will need to compile the Rust standard library:
364362

365363
```bash
366364
rustup install nightly
@@ -371,13 +369,9 @@ rustup component add rust-src
371369
You will also need a version of CPython compiled using LLVM/Clang with the same major version of LLVM as is currently used to compile nightly Rust.
372370
As of March 2025, Rust nightly uses LLVM 20.
373371

374-
The [cpython_sanity docker images](https://github.com/nascheme/cpython_sanity)
375-
contain a development environment with a pre-compiled version of CPython 3.13 or
376-
3.14 as well as optionally NumPy and SciPy, all compiled using LLVM 20 and
377-
ThreadSanitizer.
372+
The [cpython_sanity docker images](https://github.com/nascheme/cpython_sanity) contain a development environment with a pre-compiled version of CPython 3.13 or 3.14 as well as optionally NumPy and SciPy, all compiled using LLVM 20 and ThreadSanitizer.
378373

379-
After activating a nightly Rust toolchain, you can build your project using
380-
`ThreadSanitizer` with the following command:
374+
After activating a nightly Rust toolchain, you can build your project using `ThreadSanitizer` with the following command:
381375

382376
```bash
383377
RUSTFLAGS="-Zsanitizer=thread" maturin develop -Zbuild-std --target x86_64-unknown-linux-gnu

guide/src/ecosystem/logging.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Logging
22

3-
It is desirable if both the Python and Rust parts of the application end up
4-
logging using the same configuration into the same place.
3+
It is desirable if both the Python and Rust parts of the application end up logging using the same configuration into the same place.
54

65
This section of the guide briefly discusses how to connect the two languages' logging ecosystems together.
76
The recommended way for Python extension modules is to configure Rust's logger to send log messages to Python using the `pyo3-log` crate.

0 commit comments

Comments
 (0)