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


Groups > comp.lang.python > #7304

Re: how to inherit docstrings?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
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; 'test,': 0.04; 'sys': 0.05; '__name__': 0.09; 'attribute': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; 'writable': 0.09; '~ethan~': 0.09; 'output': 0.11; 'def': 0.12; '25,': 0.12; 'wrote:': 0.14; '"""method': 0.16; "%s\\n'": 0.16; "'__main__':": 0.16; "'new": 0.16; '3.2.': 0.16; 'docstring': 0.16; 'docstrings': 0.16; 'except:': 0.16; 'func():': 0.16; 'inheriting': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'received:gateway13.websitewelcome.com': 0.16; 'traceback': 0.16; '(most': 0.16; 'cc:addr:python-list': 0.17; 'work,': 0.20; 'header :In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'last):': 0.23; 'objects': 0.23; 'changed': 0.25; 'subject:how': 0.29; 'subject:?': 0.29; 'import': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.30; "skip:' 10": 0.32; 'file': 0.34; 'thinking': 0.34; 'header:User-Agent:1': 0.35; 'skip:" 10': 0.35; 'try:': 0.35; 'idea': 0.36; 'too.': 0.37; 'something': 0.37; 'change': 0.37; 'eric': 0.38; 'subject:: ': 0.38; 'skip:s 20': 0.39; 'missing': 0.40; 'really': 0.40; 'p.s.': 0.67; 'received:websitewelcome.com': 0.67; 'received:69.93': 0.67; 'skip:2 20': 0.73; 'print()': 0.84; 'snow': 0.91
Date Thu, 09 Jun 2011 09:10:38 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To Eric Snow <ericsnowcurrently@gmail.com>
Subject Re: how to inherit docstrings?
References <BANLkTin3FGoxwvH2VDOb4OhAWi2Ea3K-pA@mail.gmail.com>
In-Reply-To <BANLkTin3FGoxwvH2VDOb4OhAWi2Ea3K-pA@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:2669
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
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.54.1307635040.11593.python-list@python.org> (permalink)
Lines 85
NNTP-Posting-Host 82.94.164.166
X-Trace 1307635041 news.xs4all.nl 49045 [::ffff:82.94.164.166]:38569
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7304

Show key headers only | View raw


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~

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


Thread

Re: how to inherit docstrings? Ethan Furman <ethan@stoneleaf.us> - 2011-06-09 09:10 -0700
  Re: how to inherit docstrings? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-06-10 10:27 +1200
    Re: how to inherit docstrings? Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-09 17:16 -0600
    Re: how to inherit docstrings? Ben Finney <ben+python@benfinney.id.au> - 2011-06-10 09:23 +1000
      Re: how to inherit docstrings? Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-09 17:31 -0600

csiph-web