pganti / micheles

Automatically exported from code.google.com/p/micheles
0 stars 0 forks source link

Can't decorate method, decorator(caller, func) #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Solved with small patch

diff -r b3270ba22de7 decorator/src/decorator.py
--- a/decorator/src/decorator.py        Wed Nov 09 15:24:46 2011 +0100
+++ b/decorator/src/decorator.py        Sat Dec 10 01:14:49 2011 +0300
@@ -88,7 +88,7 @@
                 self.name = '_lambda_' 
             self.doc = func.__doc__
             self.module = func.__module__
-            if inspect.isfunction(func):
+            if inspect.isfunction(func) or inspect.ismethod(func):
                 argspec = getfullargspec(func)
                 for a in ('args', 'varargs', 'varkw', 'defaults', 'kwonlyargs',
                           'kwonlydefaults', 'annotations'):

Original issue reported on code.google.com by falko....@gmail.com on 9 Dec 2011 at 10:15

GoogleCodeExporter commented 8 years ago
Decorating methods directly is not supported by design because it is very easy 
to get confused with the self argument. You patch is too error prone, I do not 
recommend it.

Original comment by michele....@gmail.com on 10 Jan 2012 at 4:35