On Sat, Mar 8, 2008 at 4:33 PM, Anthony Tolle <[EMAIL PROTECTED]> wrote: > On Sat, Mar 8, 2008 at 3:28 PM, Steven Bethard <[EMAIL PROTECTED]> wrote: > > Why is it so crucial that "self" is the first argument? If I use a > > decorator that adds a new element to the beginning of the argument > > list, I wouldn't be surprised that I now have to write my methods as:: > > > > @add_initial_argument > > def method(new_arg, self, ...): > > ... > > That would work with class binding in Python 3.0 (i.e. "unbound" > methods). In Python 2.5, doing that with an unbound method would > throw an error.
>>> def add_initial_argument(func): ... def f(*args, **kwargs): ... return func('newarg', *args, **kwargs) ... return f ... >>> class C(object): ... @add_initial_argument ... def foo(newarg, self): ... print newarg ... >>> C().foo() newarg >>> C.foo(C()) newarg I don't see an error thrown with either the bound or unbound methods... STeVe -- I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a tiny blip on the distant coast of sanity. --- Bucky Katt, Get Fuzzy _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com