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


Groups > comp.lang.python > #7274

Re: how to inherit docstrings?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!news.glorb.com!news.astraweb.com!border6.newsrouter.astraweb.com!not-for-mail
From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: how to inherit docstrings?
References <mailman.42.1307600576.11593.python-list@python.org>
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
Date Thu, 09 Jun 2011 16:37:39 +1000
Message-ID <87k4cvy0gc.fsf@benfinney.id.au> (permalink)
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)
Cancel-Lock sha1:2rfNxJgfzodXr9zTnQg02zBFVPo=
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
Lines 29
Organization Unlimited download news at news.astraweb.com
NNTP-Posting-Host a7fa620a.news.astraweb.com
X-Trace DXC=hlCa=R>CT\>B;RYi]PcMG9L?0kYOcDh@:W\:Hm@YlDb:83@2Tm:<S08UGD@iN[Hd??^iE7nhh@8G2
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7274

Show key headers only | View raw


Eric Snow <ericsnowcurrently@gmail.com> 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 ‘__doc__’ attribute. Access that attribute to get the
docstring; re-bind that attribute to set a different docstring.

So, it's even possible to do what you ask without decorators at all:

    class Foo(object):
        def frob(self):
            """ Frobnicate thyself. """
    
    class Bar(Foo):
        def frob(self):
            pass
        frob.__doc__ = Foo.frob.__doc__

Not very elegant, and involving rather too much repetition; but not
difficult.

-- 
 \     “We are no more free to believe whatever we want about God than |
  `\         we are free to adopt unjustified beliefs about science or |
_o__)              history […].” —Sam Harris, _The End of Faith_, 2004 |
Ben Finney

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


Thread

how to inherit docstrings? Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-09 00:22 -0600
  Re: how to inherit docstrings? Ben Finney <ben+python@benfinney.id.au> - 2011-06-09 16:37 +1000
    Re: how to inherit docstrings? Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-09 01:13 -0600
      Re: how to inherit docstrings? Ben Finney <ben+python@benfinney.id.au> - 2011-06-09 17:44 +1000
        Re: how to inherit docstrings? Duncan Booth <duncan.booth@invalid.invalid> - 2011-06-09 11:23 +0000
        Re: how to inherit docstrings? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-09 14:56 +0000
          Re: how to inherit docstrings? Ben Finney <ben+python@benfinney.id.au> - 2011-06-10 07:33 +1000
            Re: how to inherit docstrings? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-10 09:25 +0000
  Re: how to inherit docstrings? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-10 16:47 +0000
    Re: how to inherit docstrings? Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-10 11:01 -0600
      Re: how to inherit docstrings? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-10 17:27 +0000
        Re: how to inherit docstrings? Eric Snow <ericsnowcurrently@gmail.com> - 2011-06-10 12:48 -0600
    Re: how to inherit docstrings? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-10 17:19 +0000

csiph-web