On Fri, Jun 8, 2012 at 2:20 PM, Alexandre Zani <alexandre.z...@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 | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com