Re: Confused with classmethods

2005-03-12 Thread Bengt Richter
On Fri, 11 Mar 2005 14:04:26 -0800, jfj <[EMAIL PROTECTED]> wrote: >Hi. > >Suppose this: > > > >def foo (x): > print x > >f = classmethod (foo) > >class A: pass > >a=A() >a.f = f > >a.f() ># TypeError: 'classmethod' object is not callable! > >### > >

Re: Confused with classmethods

2005-03-12 Thread Jong dejongconsunet
jfj schreef: Ruud wrote: So far for *how* it works. As to *why* it works like this, I don't know for sure. But my guess is that the reasoning was something as follows: if you define a function (regular or something special like a classmethod) only for an instance of a class, you obviously don't wan

Re: Confused with classmethods

2005-03-11 Thread jfj
Ruud wrote: So far for *how* it works. As to *why* it works like this, I don't know for sure. But my guess is that the reasoning was something as follows: if you define a function (regular or something special like a classmethod) only for an instance of a class, you obviously don't want to use it i

Re: Confused with classmethods

2005-03-11 Thread Steve Holden
jfj wrote: Diez B. Roggisch wrote: Moreover the documentation sais that if the first argument is an instance, its class will be used for the classmethod. OTOH, "class scope" is not a real thing in python. It is just some code which is executed and then we get its locals and use it on Class(local

Re: Confused with classmethods

2005-03-11 Thread Jong dejongconsunet
jfj schreef: Diez B. Roggisch wrote: I understand that this is a very peculiar use of classmethods but is this error intentional? Or did I completely missed the point somewhere? Note that this is not really related to classmethods. A similar "problem" exists if you want to use an ordinary function

Re: Confused with classmethods

2005-03-11 Thread jfj
Diez B. Roggisch wrote: Moreover the documentation sais that if the first argument is an instance, its class will be used for the classmethod. OTOH, "class scope" is not a real thing in python. It is just some code which is executed and then we get its locals and use it on Class(localsDict, Base

Re: Confused with classmethods

2005-03-11 Thread Diez B. Roggisch
> Not necessarily: > > def foo(cls): > print cls > f=classmethod(foo) > > class A: pass > > A.f = f > a=A() > a.f() Ahhh, yes, I see the minor difference - I didn't recognize it before. > > This works. Anyway, the confusion starts from the documentation of > classmethod(). Since classm

Re: Confused with classmethods

2005-03-11 Thread jfj
Diez B. Roggisch wrote: I understand that this is a very peculiar use of classmethods but is this error intentional? Or did I completely missed the point somewhere? A little bit: classmethods are defined in a class context. def foo(cls): print cls class A: foo = classmethod(foo) The error

Re: Confused with classmethods

2005-03-11 Thread Diez B. Roggisch
> I understand that this is a very peculiar use of > classmethods but is this error intentional? > Or did I completely missed the point somewhere? A little bit: classmethods are defined in a class context. def foo(cls): print cls class A: foo = classmethod(foo) The error you observe se

Confused with classmethods

2005-03-11 Thread jfj
Hi. Suppose this: def foo (x): print x f = classmethod (foo) class A: pass a=A() a.f = f a.f() # TypeError: 'classmethod' object is not callable! ### I understand that this is a very peculiar use of classmethods but is this error intentional? Or did