Skip to content

Commit ceb2878

Browse files
committed
Allow NULL value in pybind11_meta_setattro
1 parent 86d3e9e commit ceb2878

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

include/pybind11/detail/class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ extern "C" inline int pybind11_meta_setattro(PyObject* obj, PyObject* name, PyOb
129129
// 2. `Type.static_prop = other_static_prop` --> setattro: replace existing `static_prop`
130130
// 3. `Type.regular_attribute = value` --> setattro: regular attribute assignment
131131
const auto static_prop = (PyObject *) get_internals().static_property_type;
132-
const auto call_descr_set = descr && PyObject_IsInstance(descr, static_prop)
132+
const auto call_descr_set = descr && value && PyObject_IsInstance(descr, static_prop)
133133
&& !PyObject_IsInstance(value, static_prop);
134134
if (call_descr_set) {
135135
// Call `static_property.__set__()` instead of replacing the `static_property`.

tests/test_methods_and_attributes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ def test_static_properties():
171171
assert m.TestPropertiesOverride().def_readonly == 99
172172
assert m.TestPropertiesOverride.def_readonly_static == 99
173173

174+
# Static attributes can be deleted
175+
del m.TestPropertiesOverride.def_readonly_static
176+
assert not hasattr(m.TestPropertiesOverride, "def_readonly_static")
177+
properties_override = m.TestPropertiesOverride()
178+
del properties_override.def_readonly
179+
assert not hasattr(properties_override, "def_readonly")
180+
174181

175182
def test_static_cls():
176183
"""Static property getter and setters expect the type object as the their only argument"""

0 commit comments

Comments
 (0)