[New-bugs-announce] [issue24766] Subclass of property doesn't preserve instance __doc__ when using doc= argument
Erik Bray
report at bugs.python.org
Fri Jul 31 19:02:03 CEST 2015
New submission from Erik Bray:
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.
----------
components: Interpreter Core
files: property-doc.patch
keywords: patch
messages: 247756
nosy: erik.bray
priority: normal
severity: normal
status: open
title: Subclass of property doesn't preserve instance __doc__ when using doc= argument
Added file: http://bugs.python.org/file40086/property-doc.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24766>
_______________________________________
More information about the New-bugs-announce
mailing list