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

Nick Coghlan ncoghlan at gmail.com
Fri Jun 8 06:41:13 CEST 2012


On Fri, Jun 8, 2012 at 2:20 PM, Alexandre Zani <alexandre.zani at gmail.com> 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.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list