Re: Decorator help

2013-07-04 Thread Joshua Landau
On 4 July 2013 06:39, Peter Otten <__pete...@web.de> wrote: > Joshua Landau wrote: > >> On 3 July 2013 23:19, Joshua Landau wrote: >>> If you don't want to do that, you'd need to use introspection of a >>> remarkably hacky sort. If you want that, well, it'll take a mo. >> >> After some effort I'm

RE: Decorator help

2013-07-04 Thread Joseph L. Casale
>Well, technically it's > >func.func_closure[0].cell_contents.__name__ > >but of course you cannot know that for the general case. Hah, I admit I lacked perseverance in looking at this in PyCharms debugger as I missed that. Much appreciated! jlc -- http://mail.python.org/mailman/listinfo/python

Re: Decorator help

2013-07-03 Thread Peter Otten
Joshua Landau wrote: > On 3 July 2013 23:19, Joshua Landau wrote: >> If you don't want to do that, you'd need to use introspection of a >> remarkably hacky sort. If you want that, well, it'll take a mo. > > After some effort I'm pretty confident that the hacky way is impossible. Well, technical

RE: Decorator help

2013-07-03 Thread Joseph L. Casale
>> If you don't want to do that, you'd need to use introspection of a >> remarkably hacky sort. If you want that, well, it'll take a mo. > > After some effort I'm pretty confident that the hacky way is impossible. Hah, I fired it in PyCharm's debugger and spent a wack time myself, thanks for the c

Re: Decorator help

2013-07-03 Thread Joshua Landau
On 3 July 2013 23:19, Joshua Landau wrote: > If you don't want to do that, you'd need to use introspection of a > remarkably hacky sort. If you want that, well, it'll take a mo. After some effort I'm pretty confident that the hacky way is impossible. -- http://mail.python.org/mailman/listinfo/py

Re: Decorator help

2013-07-03 Thread Joshua Landau
On 3 July 2013 23:09, Joseph L. Casale wrote: > I have a set of methods which take args that I decorate twice, > > def wrapped(func): > def wrap(*args, **kwargs): > try: > val = func(*args, **kwargs) > # some work > except BaseException as error: >

Decorator help

2013-07-03 Thread Joseph L. Casale
I have a set of methods which take args that I decorate twice, def wrapped(func): def wrap(*args, **kwargs): try: val = func(*args, **kwargs) # some work except BaseException as error: log.exception(error) return [] return wra

Re: Decorator help

2013-03-30 Thread 88888 Dihedral
Jason Swails於 2013年3月28日星期四UTC+8上午4時33分08秒寫道: > On Wed, Mar 27, 2013 at 3:49 PM, Joseph L. Casale > wrote: > > I have a class which sets up some class vars, then several methods that are > passed in data > > and do work referencing the class vars. > > > > > > I want to decorate these meth

RE: Decorator help

2013-03-30 Thread Joseph L. Casale
> When you say "class vars", do you mean variables which hold classes? You guessed correctly, and thanks for pointing out the ambiguity in my references. > The one doesn't follow from the other. Writing decorators as classes is  > fairly unusual. Normally, they will be regular functions. I

Re: Decorator help

2013-03-27 Thread Steven D'Aprano
On Wed, 27 Mar 2013 22:38:11 -0400, Jason Swails wrote: >> The second case is the easiest. Suppose you have a class like this, >> with many methods which have code in common. Here's a toy example: >> >> >> def MyClass(object): >> x = "class attribute" >> >> def __init__(self, y): >>

Re: Decorator help

2013-03-27 Thread Jason Swails
On Wed, Mar 27, 2013 at 7:29 PM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > > The one doesn't follow from the other. Writing decorators as classes is > fairly unusual. Normally, they will be regular functions. If your > decorator needs to store so much state that it needs to

Re: Decorator help

2013-03-27 Thread Steven D'Aprano
On Wed, 27 Mar 2013 19:49:54 +, Joseph L. Casale wrote: > I have a class which sets up some class vars, then several methods that > are passed in data and do work referencing the class vars. When you say "class vars", do you mean variables which hold classes? Like "string vars" are variable

RE: Decorator help

2013-03-27 Thread Joseph L. Casale
> So decorators will never take instance variables as arguments (nor should >they, since no instance > can possibly exist when they execute). Right, I never thought of it that way, my only use of them has been trivial, in non class scenarios so far. > Bear in mind, a decorator should take a

Re: Decorator help

2013-03-27 Thread Jason Swails
On Wed, Mar 27, 2013 at 3:49 PM, Joseph L. Casale wrote: > I have a class which sets up some class vars, then several methods that > are passed in data > and do work referencing the class vars. > > > I want to decorate these methods, the decorator needs access to the class > vars, so I thought >

Re: Decorator help

2013-03-27 Thread Arnaud Delobelle
On 27 March 2013 19:49, Joseph L. Casale wrote: > I have a class which sets up some class vars, then several methods that are > passed in data > and do work referencing the class vars. > > > I want to decorate these methods, the decorator needs access to the class > vars, so I thought > about ma

Decorator help

2013-03-27 Thread Joseph L. Casale
I have a class which sets up some class vars, then several methods that are passed in data and do work referencing the class vars. I want to decorate these methods, the decorator needs access to the class vars, so I thought about making the decorator its own class and allowing it to accept args