Re: confusion with decorators

2013-02-04 Thread Duncan Booth
Dave Angel da...@davea.name 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

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, **kwargs):        

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: # untested

Re: confusion with decorators

2013-01-31 Thread Chris Angelico
On Fri, Feb 1, 2013 at 12:25 AM, Jason Swails jason.swa...@gmail.com wrote: 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

Re: confusion with decorators

2013-01-31 Thread Jason Swails
On Thu, Jan 31, 2013 at 10:28 AM, Chris Angelico ros...@gmail.com 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 declared

Re: confusion with decorators

2013-01-31 Thread Jason Swails
On Thu, Jan 31, 2013 at 11:00 AM, Jason Swails jason.swa...@gmail.comwrote: On Thu, Jan 31, 2013 at 10:28 AM, Chris Angelico ros...@gmail.com 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.

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 believe I

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 for the

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 subclass.

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

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

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, **kwargs):

Confusion about decorators

2011-12-12 Thread Henrik Faber
Hi group, I'm a bit confused regarding decorators. Recently started playing with them with Python3 and wanted (as an excercise) to implement a simple type checker first: I know there are lots of them out there, this is actually one of the reasons I chose that particular function (to compare my

Re: Confusion about decorators

2011-12-12 Thread Andrea Crotti
On 12/12/2011 01:27 PM, Henrik Faber wrote: Hi group, I'm a bit confused regarding decorators. Recently started playing with them with Python3 and wanted (as an excercise) to implement a simple type checker first: I know there are lots of them out there, this is actually one of the reasons I

Re: Confusion about decorators

2011-12-12 Thread Arnaud Delobelle
On 12 December 2011 13:27, Henrik Faber hfa...@invalid.net wrote: Hi group, I'm a bit confused regarding decorators. Recently started playing with them with Python3 and wanted (as an excercise) to implement a simple type checker first: I know there are lots of them out there, this is

Re: Confusion about decorators

2011-12-12 Thread Henrik Faber
On 12.12.2011 14:37, Andrea Crotti wrote: On 12/12/2011 01:27 PM, Henrik Faber wrote: Hi group, I'm a bit confused regarding decorators. Recently started playing with them with Python3 and wanted (as an excercise) to implement a simple type checker first: I know there are lots of them out

Re: Confusion about decorators

2011-12-12 Thread Henrik Faber
On 12.12.2011 14:45, Arnaud Delobelle wrote: Can someone please enlighten me? You can (need to?) use the descriptor protocol to deal with methods. from functools import partial [...] def __get__(self, obj, objtype): return partial(self, obj) Whoa. This is absolutely

Re: Confusion about decorators

2011-12-12 Thread Arnaud Delobelle
On 12 December 2011 13:52, Henrik Faber hfa...@invalid.net wrote: On 12.12.2011 14:45, Arnaud Delobelle wrote: Can someone please enlighten me? You can (need to?) use the descriptor protocol to deal with methods. from functools import partial [...]        def __get__(self, obj, objtype):

Re: Confusion about decorators

2011-12-12 Thread Henrik Faber
On 12.12.2011 15:01, Arnaud Delobelle wrote: I am very amazed -- I've been programming Python for about 5 years now and have never even come close to something as a descriptor protocol. Python never ceases to amaze me. Do you have any beginners guide how this works? The Pydoc (Data Model) is