Message247756
This issue is directly related to http://bugs.python.org/issue5890, the solution to which I think was incomplete.
The examples below use a trivial subclass of property (but apply as well to a less trivial one):
>>> class myproperty(property): pass
...
When using myproperty with the decorator syntax, or simply without specifying a doc= argument, the docstring is properly inherited from the getter, as was fixed by issue5890:
>>> class A:
... @myproperty
... def foo(self):
... """The foo."""
... return 1
...
>>> A.foo.__doc__
'The foo.'
However, when using the doc= argument, this behavior is broken:
>>> class B:
... def _get_foo(self): return 1
... foo = myproperty(_get_foo, doc="The foo.")
...
>>> B.foo.__doc__
>>> B.foo.__doc__ is None
True
The attached patch resolves the issue by applying the special case for subclasses more generally. If this looks good I'll add a test as well.
One thing I went back and forth on in the "if (Py_TYPE(self) != &PyProperty_Type)" block was whether or not to then deref prop->prop_doc and set it to NULL, since I don't think it's needed anymore at this point. But I decided it was ultimately harmless to leave it. |
|
Date |
User |
Action |
Args |
2015-07-31 17:02:03 | erik.bray | set | recipients:
+ erik.bray |
2015-07-31 17:02:03 | erik.bray | set | messageid: <1438362123.61.0.0930515598899.issue24766@psf.upfronthosting.co.za> |
2015-07-31 17:02:03 | erik.bray | link | issue24766 messages |
2015-07-31 17:02:03 | erik.bray | create | |
|