mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 14:59:27 +00:00
Reimplement static properties by extending PyProperty_Type
Instead of creating a new unique metaclass for each type, the builtin `property` type is subclassed to support static properties. The new setter/getters always pass types instead of instances in their `self` argument. A metaclass is still required to support this behavior, but it doesn't store any data anymore, so a new one doesn't need to be created for each class. There is now only one common metaclass which is shared by all pybind11 types.
This commit is contained in:
committed by
Wenzel Jakob
parent
a3f4a02cf8
commit
c91f8bd627
@@ -214,7 +214,10 @@ test_initializer methods_and_attributes([](py::module &m) {
|
||||
[](py::object) { return TestProperties::static_get(); })
|
||||
.def_property_static("def_property_static",
|
||||
[](py::object) { return TestProperties::static_get(); },
|
||||
[](py::object, int v) { return TestProperties::static_set(v); });
|
||||
[](py::object, int v) { TestProperties::static_set(v); })
|
||||
.def_property_static("static_cls",
|
||||
[](py::object cls) { return cls; },
|
||||
[](py::object cls, py::function f) { f(cls); });
|
||||
|
||||
py::class_<SimpleValue>(m, "SimpleValue")
|
||||
.def_readwrite("value", &SimpleValue::value);
|
||||
|
||||
Reference in New Issue
Block a user