From 5bdf6987c33ca27b52ce16b9c7337a4772c01575 Mon Sep 17 00:00:00 2001 From: mejrs Date: Thu, 5 May 2022 22:24:49 +0200 Subject: [PATCH] Delete section about immutability of pyclasses --- guide/src/class.md | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/guide/src/class.md b/guide/src/class.md index 0537063499d..4ce944911c4 100644 --- a/guide/src/class.md +++ b/guide/src/class.md @@ -604,28 +604,6 @@ Python::with_gil(|py| { }); ``` -Note that unlike class variables defined in Python code, class attributes defined in Rust cannot -be mutated at all: -```rust,should_panic -# use pyo3::prelude::*; -# #[pyclass] -# struct MyClass {} -# #[pymethods] -# impl MyClass { -# #[classattr] -# fn my_attribute() -> String { -# "hello".to_string() -# } -# } -# -Python::with_gil(|py| { - let my_class = py.get_type::(); - - // Would raise a `TypeError: can't set attributes of built-in/extension type 'MyClass'` - pyo3::py_run!(py, my_class, "my_class.my_attribute = 'foo'") -}); -``` - If the class attribute is defined with `const` code only, one can also annotate associated constants: