Re: [Python-Dev] Updated PEP 362 (Function Signature Object)

2012年6月07日 21:58:43 -0700

On Thu, Jun 7, 2012 at 9:41 PM, Nick Coghlan <[email protected]> wrote:
> On Fri, Jun 8, 2012 at 2:20 PM, Alexandre Zani <[email protected]> 
> wrote:
>> A comment on the way methods are handled. I have seen decorators that
>> do something like this:
>>
>> import functools
>>
>> def dec(f):
>>  functools.wraps(f)
>>  def decorated(*args, *kwargs):
>>    cursor = databaseCursor()
>>    return f(cursor, *args, **kwargs)
>>
>> As a result, if the decorated function has to be something like this:
>>
>> class SomeClass(object):
>> @dec
>> def func(cursor, self, whatever):
>>   ...
>>
>> Perhaps the decorator should be smarter about this and detect the fact
>> that it's dealing with a method but right now, the Signature object
>> would drop the first argument (cursor) which doesn't seem right.
>> Perhaps the decorator should set __signature__. I'm not sure.
>
> The decorator should set __signature__, since the API of the
> underlying function does not match the public API. I posted an example
> earlier in the thread on how to do that correctly.
OK, makes sense.
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan  |  [email protected]  |  Brisbane, Australia
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to