Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'pursuing': 0.05; '"""': 0.07; '2004': 0.09; 'attribute': 0.09; 'attribute.': 0.09; 'elegant,': 0.09; 'module)': 0.09; "object's": 0.09; 'writable': 0.09; '>>>': 0.12; 'examples': 0.12; 'am,': 0.14; 'wrote:': 0.14; '(whether': 0.16; '3.3.': 0.16; 'clear:': 0.16; 'decorators.': 0.16; 'docstring': 0.16; 'docstrings': 0.16; 'finney': 0.16; 'inheriting': 0.16; 'metaclasses': 0.16; 'repetition,': 0.16; '\xa0def': 0.16; 'case.': 0.16; 'traceback': 0.16; '(most': 0.16; 'cc:addr:python-list': 0.17; 'solution.': 0.19; 'writes:': 0.19; 'header:In-Reply-To:1': 0.21; 'thu,': 0.22; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'all:': 0.23; 'last):': 0.23; 'objects': 0.23; 'function': 0.25; 'url:mailman': 0.26; 'object': 0.26; "i'm": 0.27; 'message-id:@mail.gmail.com': 0.28; 'thanks': 0.28; 'subject:how': 0.29; 'subject:?': 0.29; 'sorry,': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.30; 'url:listinfo': 0.30; 'decorators': 0.30; 'received:209.85.215': 0.30; 'too': 0.33; 'rather': 0.34; 'file': 0.34; 'thinking': 0.34; 'however,': 0.34; '"",': 0.35; 'using': 0.35; '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; 'involving': 0.37; 'url:python': 0.38; 'url:org': 0.38; 'but': 0.38; 'eric': 0.38; 'subject:: ': 0.38; 'should': 0.39; 'received:209': 0.39; 'missing': 0.40; 'really': 0.40; 'science': 0.40; 'more': 0.60; 'body': 0.61; 'free': 0.63; 'link': 0.64; 'believe': 0.66; 'p.s.': 0.67; 'god': 0.76; '"some': 0.84; 'adopt': 0.84; 'beliefs': 0.84; 'difficult.': 0.91; 'harris,': 0.91; 'snow': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=WCWAeO7NJ3Z2qLDz3E5/U7UpK+eogvTkut777sYOUNM=; b=u9f3Sgagz0wZGaoEXM0Gehd6x0ud/BP0ixuXkAjpL9i1ISEWqoTSoWOf2Adgfcg8p4 xqWZdR4mmsWdxRE4rLjW4HGUl8Wn5nUc/1D1HbXW68YpISu0agQlvj9thNKAbxZEFA7a ex1Ts1fdPUXAbyvaX+jBNmHKpZG9it8Z4qlAQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=ZTFy9xk8CQOoHtIqw9djIbWssGmJ6VRGeCjZuLJ+7r5PJkaAMKhclmf42a5tslFyU+ Yuvl0uhzkH8bYYaJ+a4x03veA2sUHvLfZ1hA3R12RhwNlF+ppjazPb+GYDvauFiBdEoP 83u0QeYyFngdmNUIEmfO0pznf1YU1lxSSDKCU= MIME-Version: 1.0 In-Reply-To: <87k4cvy0gc.fsf@benfinney.id.au> References: <87k4cvy0gc.fsf@benfinney.id.au> Date: Thu, 9 Jun 2011 01:13:06 -0600 Subject: Re: how to inherit docstrings? From: Eric Snow To: Ben Finney Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Cc: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 66 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307603589 news.xs4all.nl 49039 [::ffff:82.94.164.166]:58219 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7278 On Thu, Jun 9, 2011 at 12:37 AM, Ben Finney wr= ote: > Eric Snow writes: > >> 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. > > The docstring of an object (whether function or class or module) is the > object's =91__doc__=92 attribute. Access that attribute to get the > docstring; re-bind that attribute to set a different docstring. > Sorry, I should have been more clear: >>> class X: ... "some doc" ... >>> X.__doc__ 'some doc' >>> X.__doc__ =3D "another doc" Traceback (most recent call last): File "", line 1, in AttributeError: attribute '__doc__' of 'type' objects is not writable That is on 3.3. > So, it's even possible to do what you ask without decorators at all: > > =A0 =A0class Foo(object): > =A0 =A0 =A0 =A0def frob(self): > =A0 =A0 =A0 =A0 =A0 =A0""" Frobnicate thyself. """ > > =A0 =A0class Bar(Foo): > =A0 =A0 =A0 =A0def frob(self): > =A0 =A0 =A0 =A0 =A0 =A0pass > =A0 =A0 =A0 =A0frob.__doc__ =3D Foo.frob.__doc__ > > Not very elegant, and involving rather too much repetition; but not > difficult. > Yeah, definitely you can do it directly for each case. However, the inelegance, repetition, and immodularity are exactly why I am pursuing a solution. :) (I included a link in the original message to examples of how you can already do it with metaclasses and class decorators too.) I'm just looking for a way to do it with decorators in the class body without using metaclasses or class decorators. Thanks -eric > -- > =A0\ =A0 =A0 =93We are no more free to believe whatever we want about God= than | > =A0`\ =A0 =A0 =A0 =A0 we are free to adopt unjustified beliefs about scie= nce or | > _o__) =A0 =A0 =A0 =A0 =A0 =A0 =A0history [=85].=94 =97Sam Harris, _The En= d of Faith_, 2004 | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list >