Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37997
| References | <mailman.1239.1359592452.2939.python-list@python.org> <510a053a$0$11104$c3e8da3@news.astraweb.com> <CAEk9e3rbH8Jt9pL4zS=g5uEJZiRiPKDP=cMzaC7D-c2dnMBsMw@mail.gmail.com> |
|---|---|
| Date | 2013-02-01 02:28 +1100 |
| Subject | Re: confusion with decorators |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1250.1359646129.2939.python-list@python.org> (permalink) |
On Fri, Feb 1, 2013 at 12:25 AM, Jason Swails <jason.swails@gmail.com> wrote: > On Thu, Jan 31, 2013 at 12:46 AM, Steven D'Aprano > <steve+comp.lang.python@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: >> > >> > # untested >> > class A(object): >> > 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". > > > I don't think this is right. fcn is a passed function (at least if it acts > as a decorator) that is declared locally in the _protector_decorator scope. > Since newfcn is bound in the same scope and fcn is not defined inside > newfcn, I'm pretty sure that newfcn will just grab the fcn passed into the > decorator. Yet it adds a level of indirection that achieves nothing. Why not simply: def _protector_decorator(fcn): return fcn ? I'm not understanding the purpose here. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
confusion with decorators Jason Swails <jason.swails@gmail.com> - 2013-01-30 19:34 -0500
Re: confusion with decorators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-31 05:46 +0000
Re: confusion with decorators Jason Swails <jason.swails@gmail.com> - 2013-01-31 08:25 -0500
Re: confusion with decorators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-01 10:16 +1100
Re: confusion with decorators Jason Swails <jason.swails@gmail.com> - 2013-01-31 22:13 -0500
Re: confusion with decorators Chris Angelico <rosuav@gmail.com> - 2013-02-01 02:28 +1100
Re: confusion with decorators Jason Swails <jason.swails@gmail.com> - 2013-01-31 11:00 -0500
Re: confusion with decorators Jason Swails <jason.swails@gmail.com> - 2013-01-31 12:53 -0500
Re: confusion with decorators Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-01 08:31 +1100
Re: confusion with decorators 88888 Dihedral <dihedral88888@googlemail.com> - 2013-02-01 03:26 -0800
Re: confusion with decorators 88888 Dihedral <dihedral88888@googlemail.com> - 2013-02-01 03:26 -0800
csiph-web