You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guide/src/class.md
+25-16Lines changed: 25 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -886,7 +886,7 @@ impl MyClass {
886
886
887
887
## Class attributes
888
888
889
-
To create a class attribute (also called [class variable][classattr]), a method without any arguments can be annotated with the `#[classattr]` attribute.
889
+
To create a class attribute (also called [class variable][classattr]), an associated constant can be annotated with the `#[classattr]` attribute.
890
890
891
891
```rust,no_run
892
892
# use pyo3::prelude::*;
@@ -895,25 +895,19 @@ To create a class attribute (also called [class variable][classattr]), a method
> If the method has a `Result` return type and returns an `Err`, PyO3 will panic during
932
+
class creation.
933
+
934
+
> [!NOTE]
935
+
> `#[classattr]` does not work with [`#[pyo3(warn(...))]`](./function.md#warn) attribute.
936
+
937
+
929
938
## Classes as function arguments
930
939
931
940
Class objects can be used as arguments to `#[pyfunction]`s and `#[pymethods]` in the same way as the self parameters of instance methods, i.e. they can be passed as:
0 commit comments