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: 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 User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: Eric Snow Subject: Re: how to inherit docstrings? References: In-Reply-To: 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 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: 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 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 successfully changed successfully changed <__main__.Test object at 0x00A94230> Traceback (most recent call last): File "docstring.py", line 25, in obj.__doc__ = 'new docstring' AttributeError: attribute '__doc__' of 'instancemethod' objects is not writable () Traceback (most recent call last): File "docstring.py", line 25, in obj.__doc__ = 'new docstring' AttributeError: attribute '__doc__' of 'type' objects is not writable () Traceback (most recent call last): File "docstring.py", line 25, in obj.__doc__ = '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): File "docstring.py", line 25, in obj.__doc__ = 'new docstring' AttributeError: attribute '__doc__' of 'method' objects is not writable Traceback (most recent call last): File "docstring.py", line 25, in obj.__doc__ = 'new docstring' AttributeError: attribute '__doc__' of 'type' objects is not writable successfully changed -----------------actual output---------------------------- ~Ethan~