chiark / gitweb /
documentation/python: test pybind readonly properties, for completeness.
authorVladimír Vondruš <mosra@centrum.cz>
Sat, 13 Jul 2019 20:07:49 +0000 (22:07 +0200)
committerVladimír Vondruš <mosra@centrum.cz>
Sun, 14 Jul 2019 17:11:08 +0000 (19:11 +0200)
documentation/test_python/pybind_signatures/pybind_signatures.MyClass.html
documentation/test_python/pybind_signatures/pybind_signatures.cpp

index a15394b269845b1325ff54fc7d26e0b534d69d2c..08fe68c203d253e1368f0b25be6f0d5679283d7d 100644 (file)
         <section id="properties">
           <h2><a href="#properties">Properties</a></h2>
           <dl class="m-doc">
+            <dt>
+              <a href="#bar" class="m-doc-self" id="bar">bar</a>: float <span class="m-label m-flat m-warning">get</span>
+            </dt>
+            <dd>A read-only property</dd>
             <dt>
               <a href="#foo" class="m-doc-self" id="foo">foo</a>: float <span class="m-label m-flat m-success">get set</span>
             </dt>
index ab69133da285568a973499721c17bef55c98b227..39c3a48cbc2749c13ad768adee33b633d1f98993 100644 (file)
@@ -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") = "<eh?>")
         .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_<MyClass23> pybind23{m, "MyClass23", "Testing pybind 2.3 features"};