[Python-ideas] PEP-3150
Nick Coghlan
ncoghlan at gmail.com
Thu Apr 14 14:42:55 CEST 2011
On Thu, Apr 14, 2011 at 9:47 PM, Carl M. Johnson
<cmjohnson.mailinglist at gmail.com> wrote:
> sorted_list = sorted(original_list, key=keyfunc) given:
> "A list of widgets sorted by removing whitespace and lowercasing..."
> def keyfunc(item):
> ...
>
>>>> help(sorted_list)
> "A list of widgets sorted by removing whitespace and lowercasing..."
Alas, it isn't going to be quite that simple:
>>> x = []
>>> x.__doc__ = "This is a list"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object attribute '__doc__' is read-only
>>> x = 1
>>> x.__doc__ = "This is an integer"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'int' object attribute '__doc__' is read-only
I don't see adding an extra pointer slot that will rarely be used to
the mutable builtins flying, and obviously the immutable types can't
reasonably accept a docstring that may vary by instance without
completely destroying their caching strategies.
Making the docstring available as a __doc__ variable in the given
namespace could potentially work, but I'm not sure the idea offers
much over an ordinary triple-quoted string variable at that point.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list