[New-bugs-announce] [issue12773] classes should have mutable docstrings
Eric Snow
report at bugs.python.org
Wed Aug 17 18:32:38 CEST 2011
New submission from Eric Snow <ericsnowcurrently at gmail.com>:
Apparently docstrings for classes are immutable:
>>> class X:
... "some doc"
...
>>> X.__doc__
'some doc'
>>> X.__doc__ = "another doc"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: attribute '__doc__' of 'type' objects is not writable
That is on 3.3, but apparently it's the case all the way back to 2.2.
I mentioned this on python-list and several people indicated that it
should be an unnecessary restriction [1]. I also found that this only impacts classes that do not have a custom metaclass.
Regardless, it looks like this is something that no one has take the time to address but would be nice to have done [2][3]. I found that the type_getset for __doc__ does not have a getter:
http://hg.python.org/cpython/file/default/Objects/typeobject.c#l634
I have attached a patch that adds one and fixes the problem. "make test" passed after the fix.
[1] http://mail.python.org/pipermail/python-list/2011-June/1274079.html
[2] http://mail.python.org/pipermail/python-ideas/2011-June/010462.html
[3] http://mail.python.org/pipermail/python-ideas/2011-August/011185.html
----------
components: Interpreter Core
files: mutable_class_docstrings.diff
keywords: patch
messages: 142287
nosy: eric.snow, michael.foord, ncoghlan
priority: normal
severity: normal
status: open
title: classes should have mutable docstrings
type: behavior
versions: Python 3.3
Added file: http://bugs.python.org/file22925/mutable_class_docstrings.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12773>
_______________________________________
More information about the New-bugs-announce
mailing list