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


Groups > comp.lang.python > #7273

how to inherit docstrings?

Date 2011-06-09 00:22 -0600
Subject how to inherit docstrings?
From Eric Snow <ericsnowcurrently@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.42.1307600576.11593.python-list@python.org> (permalink)

Show all headers | View raw


Sometimes when using class inheritance, I want the overriding methods
of the subclass to get the docstring of the matching method in the
base class.  You can do this with decorators (after the class
definition), with class decorators, and with metaclasses [1].

However, I was hoping for a way to do it with just function decorators
on the methods (no metaclass or class decorator).  I am not sure if
this is doable.  I realize now that this is exactly the reason I got
to thinking last week about objects being notified when they are bound
[2].

So, is there a way to do this with just decorators, or am I "stuck"
with the metaclass/class decorator route?  (It's not all that bad :)

Thanks!

-eric


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.


[1] http://code.activestate.com/recipes/577743-using-decorators-to-inherit-function-docstrings/
[2] http://mail.python.org/pipermail/python-ideas/2011-June/010446.html

Back to comp.lang.python | Previous | NextNext 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