Re: Behavior of staticmethod in Python 3

2013-11-24 Thread Antoon Pardon
Op 24-11-13 12:03, Peter Otten schreef: > Antoon Pardon wrote: > >> Op 23-11-13 10:01, Peter Otten schreef: >> >>> >>> Your script is saying that a staticmethod instance is not a callable >>> object. It need not be because >>> >>> Foo.foo() >>> >>> doesn't call the Foo.foo attribute directly, it c

Re: Behavior of staticmethod in Python 3

2013-11-24 Thread Antoon Pardon
Op 24-11-13 11:43, Peter Otten schreef: > Antoon Pardon wrote: > >> Foo.foo() being legal and Foo.foo not being callable is IMO a bug in >> python. > > Foo.foo() is legal, and Foo.foo is callable. Indeed, I had a kink in my brain which made it difficult to see where I was going wrong myself. So

Re: Behavior of staticmethod in Python 3

2013-11-24 Thread Steven D'Aprano
On Sun, 24 Nov 2013 11:30:14 +0100, Antoon Pardon wrote: > Foo.foo() is legal here. So Foo.foo is callable. Incorrect. Foo.foo() is legal for *any* identifiers Foo and foo. Since Python is an extremely dynamic language, the compiler cannot (easily, or at all) prohibit "illegal" combinations. T

Re: Behavior of staticmethod in Python 3

2013-11-24 Thread Peter Otten
Antoon Pardon wrote: > Op 23-11-13 10:01, Peter Otten schreef: > >> >> Your script is saying that a staticmethod instance is not a callable >> object. It need not be because >> >> Foo.foo() >> >> doesn't call the Foo.foo attribute directly, it calls >> >> Foo.foo.__get__(None, Foo)() > > I t

Re: Behavior of staticmethod in Python 3

2013-11-24 Thread Ian Kelly
On Sun, Nov 24, 2013 at 3:30 AM, Antoon Pardon wrote: > Op 23-11-13 22:51, Peter Otten schreef: >> Antoon Pardon wrote: >> >>> Op 23-11-13 10:01, Peter Otten schreef: >>> Your script is saying that a staticmethod instance is not a callable object. It need not be because Fo

Re: Behavior of staticmethod in Python 3

2013-11-24 Thread Peter Otten
Antoon Pardon wrote: > Foo.foo() being legal and Foo.foo not being callable is IMO a bug in > python. Foo.foo() is legal, and Foo.foo is callable. -- https://mail.python.org/mailman/listinfo/python-list

Re: Behavior of staticmethod in Python 3

2013-11-24 Thread Antoon Pardon
Op 23-11-13 22:51, Peter Otten schreef: > Antoon Pardon wrote: > >> Op 23-11-13 10:01, Peter Otten schreef: >> >>> >>> Your script is saying that a staticmethod instance is not a callable >>> object. It need not be because >>> >>> Foo.foo() >>> >>> doesn't call the Foo.foo attribute directly, it c

Re: Behavior of staticmethod in Python 3

2013-11-23 Thread Peter Otten
Antoon Pardon wrote: > Op 23-11-13 10:01, Peter Otten schreef: > >> >> Your script is saying that a staticmethod instance is not a callable >> object. It need not be because >> >> Foo.foo() >> >> doesn't call the Foo.foo attribute directly, it calls >> >> Foo.foo.__get__(None, Foo)() > > I t

Re: Behavior of staticmethod in Python 3

2013-11-23 Thread Chris Angelico
On Sun, Nov 24, 2013 at 2:00 AM, Antoon Pardon wrote: > IMO if Foo.foo() is legal then Foo.foo is callable. That the actual call > is delegated to Foo.foo.__get__(None, Foo) shouldn't matter. I absolutely agree. But isn't that already the case? I seem to be missing something here. >>> class Foo:

Re: Behavior of staticmethod in Python 3

2013-11-23 Thread Antoon Pardon
Op 23-11-13 10:01, Peter Otten schreef: > > Your script is saying that a staticmethod instance is not a callable object. > It need not be because > > Foo.foo() > > doesn't call the Foo.foo attribute directly, it calls > > Foo.foo.__get__(None, Foo)() I think you are burdening the programmer

Re: Behavior of staticmethod in Python 3

2013-11-23 Thread Peter Otten
Marco Buttu wrote: > On 11/23/2013 10:01 AM, Peter Otten wrote: > >>> In Python 3 the following two classes should be equivalent: >> Says who? >> >>> >$ cat foo.py >>> >class Foo: >>> > def foo(): >>> > pass >>> > print(callable(foo)) >>> > >>> >class Foo: >>> > @staticmet

Re: Behavior of staticmethod in Python 3

2013-11-23 Thread Steven D'Aprano
On Sat, 23 Nov 2013 09:28:43 +0100, Marco Buttu wrote: > In Python 3 the following two classes should be equivalent: They certainly are not equivalent in *any* version of Python, because staticmethods are not equivalent to instance methods. > $ cat foo.py > class Foo: > def foo(): >

Re: Behavior of staticmethod in Python 3

2013-11-23 Thread Marco Buttu
On 11/23/2013 10:01 AM, Peter Otten wrote: In Python 3 the following two classes should be equivalent: Says who? >$ cat foo.py >class Foo: > def foo(): > pass > print(callable(foo)) > >class Foo: > @staticmethod > def foo(): > pass > print(callable(f

Re: Behavior of staticmethod in Python 3

2013-11-23 Thread Peter Otten
Marco Buttu wrote: > In Python 3 the following two classes should be equivalent: Says who? > $ cat foo.py > class Foo: > def foo(): > pass > print(callable(foo)) > > class Foo: > @staticmethod > def foo(): > pass > print(callable(foo)) > > But they do

Behavior of staticmethod in Python 3

2013-11-23 Thread Marco Buttu
In Python 3 the following two classes should be equivalent: $ cat foo.py class Foo: def foo(): pass print(callable(foo)) class Foo: @staticmethod def foo(): pass print(callable(foo)) But they do not: $ python3 foo.py True False How come the metaclass does n