From: Vladimír Vondruš Date: Sat, 13 Jul 2019 20:07:49 +0000 (+0200) Subject: documentation/python: test pybind readonly properties, for completeness. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=2e2be09077a992f93906b00fcac41e536116f506;p=blog.git documentation/python: test pybind readonly properties, for completeness. --- diff --git a/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html b/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html index a15394b2..08fe68c2 100644 --- a/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html +++ b/documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html @@ -80,6 +80,10 @@

Properties

+
+ bar: float get +
+
A read-only property
foo: float get set
diff --git a/documentation/test_python/pybind_signatures/pybind_signatures.cpp b/documentation/test_python/pybind_signatures/pybind_signatures.cpp index ab69133d..39c3a48c 100644 --- a/documentation/test_python/pybind_signatures/pybind_signatures.cpp +++ b/documentation/test_python/pybind_signatures/pybind_signatures.cpp @@ -73,7 +73,8 @@ PYBIND11_MODULE(pybind_signatures, m) { .def("instance_function", &MyClass::instanceFunction, "Instance method with positional-only args") .def("instance_function_kwargs", &MyClass::instanceFunction, "Instance method with position or keyword args", py::arg("hey"), py::arg("what") = "") .def("another", &MyClass::another, "Instance method with no args, 'self' is thus position-only") - .def_property("foo", &MyClass::foo, &MyClass::setFoo, "A read/write property"); + .def_property("foo", &MyClass::foo, &MyClass::setFoo, "A read/write property") + .def_property_readonly("bar", &MyClass::foo, "A read-only property"); py::class_ pybind23{m, "MyClass23", "Testing pybind 2.3 features"};