[IPython-user] docstring of decorated functions

Tsviki Hirsh tsviki.hirsh@gmail....
Wed Jan 6 00:15:12 CST 2010


Great!
The functools.wraps is exactly what I needed, and it works perfectly.
Thanks.

On Tue, Jan 5, 2010 at 4:42 PM, Kenneth Arnold <kenneth.arnold@gmail.com>wrote:

> func? just prints func.__doc__, nothing magic.
>
> There's a simple, standard-library way to make wrapper functions:
> functools.wraps
> http://docs.python.org/library/functools.html#functools.wraps
>
> -Ken
>
>
> On Tue, Jan 5, 2010 at 2:08 AM, Brent Pedersen <bpederse@gmail.com> wrote:
>
>> 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
>> >
>> >
>> _______________________________________________
>> IPython-user mailing list
>> IPython-user@scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-user
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20100106/377f0ebc/attachment.html 


More information about the IPython-user mailing list