On Thu, Jun 7, 2012 at 9:41 PM, Nick Coghlan <ncoghlan at gmail.com> wrote: > 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. OK, makes sense. > > Cheers, > Nick. > > -- > Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4