mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 22:39:09 +00:00
Fix overriding static properties in derived classes
Fixes #775. Assignments of the form `Type.static_prop = value` should be translated to `Type.static_prop.__set__(value)` except when `isinstance(value, static_prop)`.
This commit is contained in:
@@ -75,6 +75,13 @@ struct TestProperties {
|
||||
|
||||
int TestProperties::static_value = 1;
|
||||
|
||||
struct TestPropertiesOverride : TestProperties {
|
||||
int value = 99;
|
||||
static int static_value;
|
||||
};
|
||||
|
||||
int TestPropertiesOverride::static_value = 99;
|
||||
|
||||
struct SimpleValue { int value = 1; };
|
||||
|
||||
struct TestPropRVP {
|
||||
@@ -219,6 +226,11 @@ test_initializer methods_and_attributes([](py::module &m) {
|
||||
[](py::object cls) { return cls; },
|
||||
[](py::object cls, py::function f) { f(cls); });
|
||||
|
||||
py::class_<TestPropertiesOverride, TestProperties>(m, "TestPropertiesOverride")
|
||||
.def(py::init<>())
|
||||
.def_readonly("def_readonly", &TestPropertiesOverride::value)
|
||||
.def_readonly_static("def_readonly_static", &TestPropertiesOverride::static_value);
|
||||
|
||||
py::class_<SimpleValue>(m, "SimpleValue")
|
||||
.def_readwrite("value", &SimpleValue::value);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user