Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7331

__doc__ immutable for classes (was: Re: how to inherit docstrings?)

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ericsnowcurrently@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'classes.': 0.05; 'sys': 0.05; 'wrapper': 0.07; '__name__': 0.09; 'attribute': 0.09; 'writable': 0.09; '~ethan~': 0.09; 'output': 0.11; 'def': 0.12; '25,': 0.12; 'am,': 0.14; 'wrote:': 0.14; "%s\\n'": 0.16; "'__main__':": 0.16; "'new": 0.16; '3.2.': 0.16; 'docstring': 0.16; 'docstrings': 0.16; 'func():': 0.16; 'function?': 0.16; 'furman': 0.16; 'inheriting': 0.16; 'subject:?)': 0.16; 'subject:classes': 0.16; '\xa0def': 0.16; '\xa0for': 0.16; 'subject:was': 0.16; 'traceback': 0.16; '(most': 0.16; 'cc:addr :python-list': 0.17; 'work,': 0.20; 'seems': 0.21; "haven't": 0.22; 'thu,': 0.22; 'cc:2**0': 0.22; 'maybe': 0.23; 'last):': 0.23; 'objects': 0.23; 'changed': 0.25; 'message- id:@mail.gmail.com': 0.28; 'thanks': 0.28; 'subject:how': 0.29; 'bound': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.30; 'received:209.85.215': 0.30; "skip:' 10": 0.32; 'thinking': 0.34; 'however,': 0.34; 'that,': 0.34; 'skip:" 10': 0.35; '8bit%:5': 0.36; 'idea': 0.36; '8bit%:8': 0.36; 'too.': 0.37; 'received:google.com': 0.37; 'something': 0.37; 'change': 0.37; 'received:209.85': 0.37; 'but': 0.38; 'eric': 0.38; 'subject:: ': 0.38; 'case,': 0.39; 'subject: (': 0.39; 'should': 0.39; 'received:209': 0.39; 'missing': 0.40; 'really': 0.40; 'more': 0.60; 'love': 0.62; 'auto': 0.63; 'p.s.': 0.67; 'skip:2 20': 0.73; 'snow': 0.91; 'updated.': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=tyeCbWCmzAQSRK9ujF2EQlgNQy1Vm3PkPDNg66MZRB0=; b=clQYvtjYVZlFQnJ3qTDcFvBswMzSA5XmY0QMIe8cYrH0nIgDeHMoPtWh4j5TRVzCmH jvnq9csKcLoQShvVqovhv2LnJUYrR2/cQPKi9/efNQfnz3AkMJG0e/E8FJoO86K6qqqJ knExxDynfsgZFfTcTALL0c214DjZwCUXax/n4=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=a0U/EreVXpc0C/jDI6zlwmrk+h9GhH8SZ4j+A0uKBpC5urOz7VGN+pwRXrxwxU8JKs qi071u5b7Iwhehz5BQjbtEYCXsSKnlYD6Yp9PlVTnBauae5suvmmJ5EuUR0ylHrXdHI/ yCNiyUp9YxSajZoPqTRlujireXcL250OxXEv4=
MIME-Version 1.0
Date Thu, 9 Jun 2011 17:29:35 -0600
Subject __doc__ immutable for classes (was: Re: how to inherit docstrings?)
From Eric Snow <ericsnowcurrently@gmail.com>
To Ethan Furman <ethan@stoneleaf.us>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.65.1307662177.11593.python-list@python.org> (permalink)
Lines 101
NNTP-Posting-Host 82.94.164.166
X-Trace 1307662177 news.xs4all.nl 49183 [::ffff:82.94.164.166]:34234
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7331

Show key headers only | View raw


On Thu, Jun 9, 2011 at 10:10 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
> Eric Snow wrote:
>>
>> p.s. Am I missing something or can you really not change the docstring
>> of a class?  I was thinking about the idea of inheriting class
>> docstrings too.
>
> 8<--------------------------------------------------------
> """module level docstring"""
>
> def func():
>    """function level docstring"""
>
> class Test(object):
>    """class level docstring"""
>    def meth(self):
>        """method level docstring"""
>
>
> if __name__ == '__main__':
>    import sys
>    import traceback
>    hmmm = (
>        sys.modules['__main__'],
>        func,
>        Test(),
>        Test().meth,
>        Test,
>        Test.meth,
>        )
>    for obj in hmmm:
>        try:
>            obj.__doc__ = 'new docstring'
>            print('successfully changed %s\n' % obj)
>        except:
>            traceback.print_exc()
>            print()
> 8<--------------------------------------------------------
>
> Tested from 2.5 - 3.2.  The first three always work, the last one works in
> 3.1+, the fourth and fifth always fail.
>
> -----------------actual output for 2.5--------------------
> successfully changed <module '__main__' from 'docstring.py'>
>
> successfully changed <function func at 0x00A8F570>
>
> successfully changed <__main__.Test object at 0x00A94230>
>
> Traceback (most recent call last):
>  File "docstring.py", line 25, in <module>
>    obj.__doc__ = 'new docstring'
> AttributeError: attribute '__doc__' of 'instancemethod' objects is not
> writable
> ()
> Traceback (most recent call last):
>  File "docstring.py", line 25, in <module>
>    obj.__doc__ = 'new docstring'
> AttributeError: attribute '__doc__' of 'type' objects is not writable
> ()
> Traceback (most recent call last):
>  File "docstring.py", line 25, in <module>
>    obj.__doc__ = 'new docstring'
> AttributeError: attribute '__doc__' of 'instancemethod' objects is not
> writable
> ()
> -----------------actual output for 3.2--------------------
> successfully changed <module '__main__' from 'docstring.py'>
>
> successfully changed <function func at 0x00BE6F60>
>
> successfully changed <__main__.Test object at 0x00BFE730>
>
> Traceback (most recent call last):
>  File "docstring.py", line 25, in <module>
>    obj.__doc__ = 'new docstring'
> AttributeError: attribute '__doc__' of 'method' objects is not writable
>
> Traceback (most recent call last):
>  File "docstring.py", line 25, in <module>
>    obj.__doc__ = 'new docstring'
> AttributeError: attribute '__doc__' of 'type' objects is not writable
>
> successfully changed <function meth at 0x00BE6ED0>
> -----------------actual output----------------------------
>
> ~Ethan~
>

Thanks for looking up all of that, Ethan!  I would love to see __doc__
writable for classes.  But for "method" objects  (really a wrapper for
bound functions) would it change the __doc__ of the wrapper or of the
bound function?  Seems like it is analogous to the Test().__doc__
case, so the wrapper would be updated.  However, I haven't really had
a need to do that before, so I don't know which makes more sense.

Should I take this to python-ideas?  And maybe Greg's thought of auto
inheriting __doc__?

-eric

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

__doc__ immutable for classes (was: Re: how to inherit docstrings?) Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-09 17:29 -0600
  Re: __doc__ immutable for classes (was: Re: how to inherit docstrings?) Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-06-10 19:31 +1200
    Re: __doc__ immutable for classes Terry Reedy <tjreedy@udel.edu> - 2011-06-10 21:17 -0400

csiph-web