Issue 12773: classes should have mutable docstrings (original) (raw)

Issue12773

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/56982

classification

Title: classes should have mutable docstrings
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.3

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eric.snow, michael.foord, ncoghlan, python-dev
Priority: normal Keywords: patch

Created on 2011-08-17 16:32 by eric.snow, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mutable_class_docstrings.diff eric.snow,2011-08-17 16:32 review
Messages (2)
msg142287 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2011-08-17 16:32
Apparently docstrings for classes are immutable: >>> class X: ... "some doc" ... >>> X.__doc__ 'some doc' >>> X.__doc__ = "another doc" Traceback (most recent call last): File "", line 1, in 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
msg142288 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-08-17 17:04
New changeset ed2511c23dae by Benjamin Peterson in branch 'default': make __doc__ mutable on heaptypes (closes #12773) http://hg.python.org/cpython/rev/ed2511c23dae
History
Date User Action Args
2022-04-11 14:57:20 admin set github: 56982
2011-08-17 17:04:29 python-dev set status: open -> closednosy: + python-devmessages: + resolution: fixedstage: resolved
2011-08-17 16:32:38 eric.snow create

Supported by The Python Software Foundation,
Powered by Roundup

Copyright © 1990-2022, Python Software Foundation
Legal Statements