[IPython-user] docstring of decorated functions

Brent Pedersen bpederse@gmail....
Tue Jan 5 01:08:12 CST 2010


On Mon, Jan 4, 2010 at 10:53 PM, Tsviki Hirsh <tsviki.hirsh@gmail.com> wrote:
> Dear list,
> The magic ? and ?? commands are among the most useful features in ipython
> (at least for me),
> I'm also using them to read my selfdocumentation on my own functions.
> Therefore I was surprised to learn that you cannot read the doc string of a
> decorated function using ? or ??
> for example, consider this decorator and function
>
> def deco(f):
> '''decorator docstring'''
> def _deco(*args,**kwargs):
> '''decorator inner function docstring'''
> print 'args=',args
> return f(*args,**kwargs)
> return _deco
> @deco
> def myfunc(x,y):
> '''function docstring'''
> return x+y
>
> if I try to call myfunc docstring using ? I get:
>
> In [18]: exem.myfunc?
> Type: function
> Base Class: <type 'function'>
> String Form: <function _deco at 0x868a5a4>
> Namespace: Interactive
> File: /home/tsviki/exem.py
> Definition: exem.myfunc(*args, **kwargs)
> Docstring:
>     decorator inner function docstring
>
> and if I try to call ??, it just gives me the decorator inner function.
> Is there a way to overlap this?
> linking the decorator __doc__ to myfunc.__doc__ won't help in case that I
> have several functions that use the same decorator.
> Any help?

hi,
decorate your decorator :)
http://pypi.python.org/pypi/decorator

i think something like:

from decorator import decorator

@decorator
def deco(f):
    '''decorator docstring'''
    @decorator
    def _deco(*args,**kwargs):
        '''decorator inner function docstring'''
        print 'args=',args
        return f(*args,**kwargs)
    return _deco




> Thanks a lot
> Tsviki Hirsh
>
> _______________________________________________
> IPython-user mailing list
> IPython-user@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
>


More information about the IPython-user mailing list