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: 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 To: Ethan Furman Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Thu, Jun 9, 2011 at 10:10 AM, Ethan Furman wrote: > Eric Snow wrote: >> >> p.s. Am I missing something or can you really not change the docstring >> of a class? =A0I was thinking about the idea of inheriting class >> docstrings too. > > 8<-------------------------------------------------------- > """module level docstring""" > > def func(): > =A0 =A0"""function level docstring""" > > class Test(object): > =A0 =A0"""class level docstring""" > =A0 =A0def meth(self): > =A0 =A0 =A0 =A0"""method level docstring""" > > > if __name__ =3D=3D '__main__': > =A0 =A0import sys > =A0 =A0import traceback > =A0 =A0hmmm =3D ( > =A0 =A0 =A0 =A0sys.modules['__main__'], > =A0 =A0 =A0 =A0func, > =A0 =A0 =A0 =A0Test(), > =A0 =A0 =A0 =A0Test().meth, > =A0 =A0 =A0 =A0Test, > =A0 =A0 =A0 =A0Test.meth, > =A0 =A0 =A0 =A0) > =A0 =A0for obj in hmmm: > =A0 =A0 =A0 =A0try: > =A0 =A0 =A0 =A0 =A0 =A0obj.__doc__ =3D 'new docstring' > =A0 =A0 =A0 =A0 =A0 =A0print('successfully changed %s\n' % obj) > =A0 =A0 =A0 =A0except: > =A0 =A0 =A0 =A0 =A0 =A0traceback.print_exc() > =A0 =A0 =A0 =A0 =A0 =A0print() > 8<-------------------------------------------------------- > > Tested from 2.5 - 3.2. =A0The first three always work, the last one works= in > 3.1+, the fourth and fifth always fail. > > -----------------actual output for 2.5-------------------- > successfully changed > > successfully changed > > successfully changed <__main__.Test object at 0x00A94230> > > Traceback (most recent call last): > =A0File "docstring.py", line 25, in > =A0 =A0obj.__doc__ =3D 'new docstring' > AttributeError: attribute '__doc__' of 'instancemethod' objects is not > writable > () > Traceback (most recent call last): > =A0File "docstring.py", line 25, in > =A0 =A0obj.__doc__ =3D 'new docstring' > AttributeError: attribute '__doc__' of 'type' objects is not writable > () > Traceback (most recent call last): > =A0File "docstring.py", line 25, in > =A0 =A0obj.__doc__ =3D 'new docstring' > AttributeError: attribute '__doc__' of 'instancemethod' objects is not > writable > () > -----------------actual output for 3.2-------------------- > successfully changed > > successfully changed > > successfully changed <__main__.Test object at 0x00BFE730> > > Traceback (most recent call last): > =A0File "docstring.py", line 25, in > =A0 =A0obj.__doc__ =3D 'new docstring' > AttributeError: attribute '__doc__' of 'method' objects is not writable > > Traceback (most recent call last): > =A0File "docstring.py", line 25, in > =A0 =A0obj.__doc__ =3D 'new docstring' > AttributeError: attribute '__doc__' of 'type' objects is not writable > > successfully changed > -----------------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