Skip to content

Commit 0302ffb

Browse files
committed
Fix __doc__ assignment in property subclass
1 parent 8730abc commit 0302ffb

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

Objects/descrobject.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,20 +1804,25 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
18041804
self->getter_doc = 1;
18051805
}
18061806

1807-
if (prop_doc != NULL && prop_doc != Py_None) {
1808-
if (Py_IS_TYPE(self, &PyProperty_Type)) {
1807+
if (Py_IS_TYPE(self, &PyProperty_Type)) {
1808+
if (prop_doc != NULL && prop_doc != Py_None) {
18091809
Py_XSETREF(self->prop_doc, prop_doc);
1810-
} else {
1811-
/* If this is a property subclass, put __doc__
1812-
in dict of the subclass instance instead,
1813-
otherwise it gets shadowed by __doc__ in the
1814-
class's dict. */
1815-
int err = PyObject_SetAttr(
1816-
(PyObject *)self, &_Py_ID(__doc__), prop_doc);
1817-
Py_XDECREF(prop_doc);
1818-
if (err < 0)
1819-
return -1;
18201810
}
1811+
} else {
1812+
/* If this is a property subclass, put __doc__
1813+
in dict of the subclass instance instead,
1814+
otherwise it gets shadowed by __doc__ in the
1815+
class's dict. */
1816+
1817+
if (prop_doc == NULL) {
1818+
prop_doc = Py_None;
1819+
Py_INCREF(prop_doc);
1820+
}
1821+
int err = PyObject_SetAttr(
1822+
(PyObject *)self, &_Py_ID(__doc__), prop_doc);
1823+
Py_XDECREF(prop_doc);
1824+
if (err < 0)
1825+
return -1;
18211826
}
18221827

18231828
return 0;

0 commit comments

Comments
 (0)