Re: Determining if a function is a method of a class within a decorator

2009-07-05 Thread Piet van Oostrum
> David Hirschfield (DH) wrote: >DH> Yeah, it definitely seems like having two separate decorators is the >DH> solution. But the strange thing is that I found this snippet after some >DH> deep googling, that seems to do something *like* what I want, though I >DH> don't understand the descript

Re: Determining if a function is a method of a class within a decorator

2009-07-02 Thread Jeremiah Dodds
On Wed, Jul 1, 2009 at 2:14 AM, David Hirschfield wrote: > Unfortunately that still requires two separate decorators, when I was > hoping there was a way to determine if I was handed a function or method > from within the same decorator. > > Seems like there really isn't, so two decorators is th

Re: Determining if a function is a method of a class within a decorator

2009-06-30 Thread David Hirschfield
Unfortunately that still requires two separate decorators, when I was hoping there was a way to determine if I was handed a function or method from within the same decorator. Seems like there really isn't, so two decorators is the way to go. Thanks, -David Carl Banks wrote: On Jun 29, 6:01 pm

Re: Determining if a function is a method of a class within a decorator

2009-06-30 Thread Carl Banks
On Jun 29, 6:01 pm, David Hirschfield wrote: > So is there > a pattern I can follow that will allow me to determine whether the > objects I'm given are plain functions or belong to a class? > > Thanks in advance, class HomemadeUnboundMethod(object): def __init__(self,func): self.fun

Re: Determining if a function is a method of a class within a decorator

2009-06-30 Thread Terry Reedy
I do not like top posting. Some thoughts in randon order: Introspection is version-specific. Call-time introspection is different from definition-time introspection. Do what is easy and works. Do not use recipes that depend on version-specific stuff you do not understand. Code objects, I believe

Re: Determining if a function is a method of a class within a decorator

2009-06-29 Thread Steven D'Aprano
On Mon, 29 Jun 2009 18:01:29 -0700, David Hirschfield wrote: > I'm having a little problem with some python metaprogramming. I want to > have a decorator which I can use either with functions or methods of > classes, which will allow me to swap one function or method for another. > It works as I w

Re: Determining if a function is a method of a class within a decorator

2009-06-29 Thread David Hirschfield
Yeah, it definitely seems like having two separate decorators is the solution. But the strange thing is that I found this snippet after some deep googling, that seems to do something *like* what I want, though I don't understand the descriptor stuff nearly well enough to get what's happening:

Re: Determining if a function is a method of a class within a decorator

2009-06-29 Thread Terry Reedy
David Hirschfield wrote: I'm having a little problem with some python metaprogramming. I want to have a decorator which I can use either with functions or methods of classes, which will allow me to swap one function or method for another. It works as I want it to, except that I want to be able

Determining if a function is a method of a class within a decorator

2009-06-29 Thread David Hirschfield
I'm having a little problem with some python metaprogramming. I want to have a decorator which I can use either with functions or methods of classes, which will allow me to swap one function or method for another. It works as I want it to, except that I want to be able to do some things a littl