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:
Dean Moldovan
2017-04-06 23:45:12 +02:00
parent db200955b9
commit e0e2ea3378
3 changed files with 28 additions and 2 deletions

View File

@@ -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);