homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tdimson
Recipients tdimson
Date 2008年04月02日.02:23:48
SpamBayes Score 0.088405825
Marked as misclassified No
Message-id <1207103039.83.0.312467912668.issue2533@psf.upfronthosting.co.za>
In-reply-to
Content
Having a peculiar issue (exception raised despite being valid) when
defining a decorator that takes a class method as a callback. Here is a
cooked example:
def decorator( callback ):
 def inner(func):
 def application( *args, **kwargs ):
 callback(*args,**kwargs)
 func(*args,**kwargs)
 return application
 return inner
class DecorateMe:
 @decorator( callback=DecorateMe.callback )
 def youBet( self ):
 pass
 def callback( self ):
 print "Hello!"
>>> DecorateMe().youBet()
Traceback (most recent call last):
 File "<pyshell#0>", line 1, in <module>
 DecorateMe().youBet()
 File "C:\Python25\badpython.py", line 4, in application
 callback(*args,**kwargs)
TypeError: unbound method callback() must be called with DecorateMe
instance as first argument (got DecorateMe instance instead)
If you change the line "callback=DecorateMe.callback" to
"callback=lambda x: DecorateMe.callback(x)" python gives you:
>>> DecorateMe().youBet()
Hello!
Mysteriously, I did encounter this during my coding with a non-cooked
decorator.
History
Date User Action Args
2008年04月02日 02:24:00tdimsonsetspambayes_score: 0.0884058 -> 0.088405825
recipients: + tdimson
2008年04月02日 02:23:59tdimsonsetspambayes_score: 0.0884058 -> 0.0884058
messageid: <1207103039.83.0.312467912668.issue2533@psf.upfronthosting.co.za>
2008年04月02日 02:23:49tdimsonlinkissue2533 messages
2008年04月02日 02:23:48tdimsoncreate

AltStyle によって変換されたページ (->オリジナル) /