Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Lib/test/test_pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,25 @@ def test_issue8225(self):
result, doc_loc = get_pydoc_text(xml.etree)
self.assertEqual(doc_loc, "", "MODULE DOCS incorrectly includes a link")

def test_issue41287(self):
Comment thread
sizmailov marked this conversation as resolved.
Resolved
# Test issue41287 to ensure property subclass handles `doc` argument correctly

class Property(property):
Comment thread
sizmailov marked this conversation as resolved.
Resolved
"""A subclass of builtin property"""

self.assertEqual(Property.__doc__, "A subclass of builtin property", "Docstring of `property` subclass is ignored")

doc = Property(None, None, None, "issue 41287 is fixed").__doc__
self.assertEqual(doc, "issue 41287 is fixed", "Subclasses of `property` ignores `doc` constructor argument")

def getter(x):
"""Getter docstring"""
doc = Property(getter, None, None, "issue 41287 is fixed").__doc__
self.assertEqual(doc, "issue 41287 is fixed", "Getter overrides explicit property docstring docstring")

doc = Property(getter, None, None, None).__doc__
Comment thread
sizmailov marked this conversation as resolved.
Resolved
self.assertEqual(doc, "Getter docstring", "Getter docstring is not picked-up")

def test_getpager_with_stdin_none(self):
previous_stdin = sys.stdin
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle doc argument of property.__init__ in subclasses
Comment thread
sizmailov marked this conversation as resolved.
Resolved
39 changes: 22 additions & 17 deletions Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1781,39 +1781,44 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
Py_XINCREF(fget);
Py_XINCREF(fset);
Py_XINCREF(fdel);
Py_XINCREF(doc);

Py_XSETREF(self->prop_get, fget);
Py_XSETREF(self->prop_set, fset);
Py_XSETREF(self->prop_del, fdel);
Py_XSETREF(self->prop_doc, doc);
Py_XSETREF(self->prop_doc, NULL);
Py_XSETREF(self->prop_name, NULL);

self->getter_doc = 0;
PyObject *get_doc = NULL;
Comment thread
sizmailov marked this conversation as resolved.
Resolved

/* if no docstring given and the getter has one, use that one */
if ((doc == NULL || doc == Py_None) && fget != NULL) {
PyObject *get_doc;
int rc = _PyObject_LookupAttr(fget, &_Py_ID(__doc__), &get_doc);
if (rc <= 0) {
return rc;
}
if (Py_IS_TYPE(self, &PyProperty_Type)) {
Py_XSETREF(self->prop_doc, get_doc);
}
else {
/* If this is a property subclass, put __doc__
in dict of the subclass instance instead,
otherwise it gets shadowed by __doc__ in the
class's dict. */
int err = PyObject_SetAttr(
(PyObject *)self, &_Py_ID(__doc__), get_doc);
Py_DECREF(get_doc);
if (err < 0)
return -1;
}
self->getter_doc = 1;
Comment thread
sizmailov marked this conversation as resolved.
Resolved
}
else {
get_doc = doc;
Py_XINCREF(get_doc);
}


Comment thread
sizmailov marked this conversation as resolved.
Resolved
if (Py_IS_TYPE(self, &PyProperty_Type)) {
Py_XSETREF(self->prop_doc, get_doc);
}
else {
/* If this is a property subclass, put __doc__
in dict of the subclass instance instead,
otherwise it gets shadowed by __doc__ in the
class's dict. */
int err = PyObject_SetAttr(
(PyObject *)self, &_Py_ID(__doc__), get_doc);
Comment thread
sizmailov marked this conversation as resolved.
Resolved
Py_XDECREF(get_doc);
if (err < 0)
return -1;
}

return 0;
}
Expand Down