inspect feature

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Oct 14 09:06:51 CEST 2008


En Fri, 10 Oct 2008 14:18:53 -0300, Aaron "Castironpi" Brady  
<castironpi at gmail.com> escribió:
> On Oct 10, 3:36 am, Bruno Desthuilliers <bruno.
> 42.desthuilli... at websiteburo.invalid> wrote:

>> I don't get what you're after ??? The decorator has full access to both
>> the actual params *and* the function's signature (via
>> inspect.getargspec). So your initial question "if you wanted a decorator
>> that examines the parameters to a function" seems fully answered. You
>> will indeed have to write a couple lines of code if you want the same
>> formating as the one you'd get with inspect.currentframe(), but what ?
>>
>> FWIW, Michele Simionato's decorator module has some trick to allow for
>> signature-preserving decorators, so you may want to have a look - but
>> I'm not sure if this would solve your problem - at least in a sane way.
>
> It's not exactly the next Millennium problem, but there are some
> substantial checks you have to do on a per-parameter basis to see the
> same thing that a function sees, when all you have is *args, **kwargs.
>
> You are wrapping a function with this signature:
>
> def f( a, b, c= None, *d, **e ):
>
> You want to find out the values of 'a', 'b', and 'c' in a decorator.
> You have these calls:
>
> f( 0, 1, 'abc', 'def', h= 'ghi' )
> f( 0, 1 )
> f( 0, 1, h= 'abc' )
> f( 0, 1, 'abc', c= 'def' ) #raise TypeError: multiple values
>
> How do you determine 'a', 'b', and 'c'?

I'm afraid you'll have to duplicate the logic described here:  
http://docs.python.org/reference/expressions.html#id9
To my knowledge, there is no available Python code (in the stdlib or  
something) that already does that.

-- 
Gabriel Genellina




More information about the Python-list mailing list