Re: confusion with decorators

2013-02-04 Thread Duncan Booth
Dave Angel wrote: > The decorator function will execute while *compiling* the class A, and > the one in class B is unreferenced. No, the decorator function is called when *executing* the class body of A. Compilation could have happened weeks earlier. It really does make it a lot easier to und

Re: confusion with decorators

2013-02-01 Thread 88888 Dihedral
Jason Swails於 2013年1月31日星期四UTC+8上午8時34分03秒寫道: > Hello, > > > I was having some trouble understanding decorators and inheritance and all > that.  This is what I was trying to do: > > > > # untested > class A(object): >    def _protector_decorator(fcn): > >       def newfcn(self, *args, **kwar

Re: confusion with decorators

2013-01-31 Thread Jason Swails
On Thu, Jan 31, 2013 at 6:16 PM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > > Normally, subclasses should extend functionality, not take it away. A > fundamental principle of OO design is that anywhere you could sensibly > allow an instance, should also be able to use a subcl

Re: confusion with decorators

2013-01-31 Thread Steven D'Aprano
Jason Swails wrote: > On Thu, Jan 31, 2013 at 12:46 AM, Steven D'Aprano < > steve+comp.lang.pyt...@pearwood.info> wrote: >> Well, that surely isn't going to work, because it always decorates the >> same function, the global "fcn". > > I don't think this is right. It certainly isn't. Sorry fo

Re: confusion with decorators

2013-01-31 Thread Steven D'Aprano
Steven D'Aprano wrote: >> def _protector_decorator(fcn): >> def newfcn(self, *args, **kwargs): >> return fcn(self, *args, **kwargs) >> return newfcn > > Well, that surely isn't going to work, because it always decorates the > same function, the global "fcn". Good grief, I can't b

Re: confusion with decorators

2013-01-31 Thread Jason Swails
On Thu, Jan 31, 2013 at 11:00 AM, Jason Swails wrote: > > > On Thu, Jan 31, 2013 at 10:28 AM, Chris Angelico wrote: > >> >> >> Well, that surely isn't going to work, because it always decorates the >> >> same function, the global "fcn". >> > >> > >> > I don't think this is right. fcn is a passed

Re: confusion with decorators

2013-01-31 Thread Jason Swails
On Thu, Jan 31, 2013 at 10:28 AM, Chris Angelico wrote: > > >> Well, that surely isn't going to work, because it always decorates the > >> same function, the global "fcn". > > > > > > I don't think this is right. fcn is a passed function (at least if it > acts > > as a decorator) that is declare

Re: confusion with decorators

2013-01-31 Thread Chris Angelico
On Fri, Feb 1, 2013 at 12:25 AM, Jason Swails wrote: > On Thu, Jan 31, 2013 at 12:46 AM, Steven D'Aprano > wrote: >> >> On Wed, 30 Jan 2013 19:34:03 -0500, Jason Swails wrote: >> >> > Hello, >> > >> > I was having some trouble understanding decorators and inheritance and >> > all that. This is w

Re: confusion with decorators

2013-01-31 Thread Jason Swails
On Thu, Jan 31, 2013 at 12:46 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Wed, 30 Jan 2013 19:34:03 -0500, Jason Swails wrote: > > > Hello, > > > > I was having some trouble understanding decorators and inheritance and > > all that. This is what I was trying to do: > >

Re: confusion with decorators

2013-01-30 Thread Steven D'Aprano
On Wed, 30 Jan 2013 19:34:03 -0500, Jason Swails wrote: > Hello, > > I was having some trouble understanding decorators and inheritance and > all that. This is what I was trying to do: > > # untested > class A(object): >def _protector_decorator(fcn): > def newfcn(self, *args, **kwarg

Re: confusion with decorators

2013-01-30 Thread Dave Angel
On 01/30/2013 07:34 PM, Jason Swails wrote: Hello, I was having some trouble understanding decorators and inheritance and all that. This is what I was trying to do: # untested class A(object): def _protector_decorator(fcn): def newfcn(self, *args, **kwargs): return fcn(sel

confusion with decorators

2013-01-30 Thread Jason Swails
Hello, I was having some trouble understanding decorators and inheritance and all that. This is what I was trying to do: # untested class A(object): def _protector_decorator(fcn): def newfcn(self, *args, **kwargs): return fcn(self, *args, **kwargs) return newfcn @_pro