mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Enable static properties (py::metaclass) by default
Now that only one shared metaclass is ever allocated, it's extremely cheap to enable it for all pybind11 types. * Deprecate the default py::metaclass() since it's not needed anymore. * Allow users to specify a custom metaclass via py::metaclass(handle).
This commit is contained in:
committed by
Wenzel Jakob
parent
08cbe8dfed
commit
dd01665e5a
@@ -202,7 +202,7 @@ test_initializer methods_and_attributes([](py::module &m) {
|
||||
.def("__str__", &ExampleMandA::toString)
|
||||
.def_readwrite("value", &ExampleMandA::value);
|
||||
|
||||
py::class_<TestProperties>(m, "TestProperties", py::metaclass())
|
||||
py::class_<TestProperties>(m, "TestProperties")
|
||||
.def(py::init<>())
|
||||
.def_readonly("def_readonly", &TestProperties::value)
|
||||
.def_readwrite("def_readwrite", &TestProperties::value)
|
||||
@@ -228,7 +228,7 @@ test_initializer methods_and_attributes([](py::module &m) {
|
||||
auto static_set2 = [](py::object, int v) { TestPropRVP::sv2.value = v; };
|
||||
auto rvp_copy = py::return_value_policy::copy;
|
||||
|
||||
py::class_<TestPropRVP>(m, "TestPropRVP", py::metaclass())
|
||||
py::class_<TestPropRVP>(m, "TestPropRVP")
|
||||
.def(py::init<>())
|
||||
.def_property_readonly("ro_ref", &TestPropRVP::get1)
|
||||
.def_property_readonly("ro_copy", &TestPropRVP::get2, rvp_copy)
|
||||
@@ -245,6 +245,10 @@ test_initializer methods_and_attributes([](py::module &m) {
|
||||
.def_property_readonly("rvalue", &TestPropRVP::get_rvalue)
|
||||
.def_property_readonly_static("static_rvalue", [](py::object) { return SimpleValue(); });
|
||||
|
||||
struct MetaclassOverride { };
|
||||
py::class_<MetaclassOverride>(m, "MetaclassOverride", py::metaclass((PyObject *) &PyType_Type))
|
||||
.def_property_readonly_static("readonly", [](py::object) { return 1; });
|
||||
|
||||
#if !defined(PYPY_VERSION)
|
||||
py::class_<DynamicClass>(m, "DynamicClass", py::dynamic_attr())
|
||||
.def(py::init());
|
||||
|
||||
Reference in New Issue
Block a user