why descriptors? (WAS: Make staticmethod objects callable?)

2006-03-01 Thread Steven Bethard
Steven Bethard wrote: > (For anyone else out there reading who doesn't already know this, > Steven D'Aprano's comments are easily explained by noting that the > __get__ method of staticmethod objects returns functions, and classes > always call the __get__ methods of descriptors when those desc

Re: Make staticmethod objects callable?

2006-03-01 Thread Steven D'Aprano
On Wed, 01 Mar 2006 08:32:20 -0700, Steven Bethard wrote: > (For anyone else out there reading who doesn't already know this, Steven > D'Aprano's comments are easily explained by noting that the __get__ > method of staticmethod objects returns functions, and classes always > call the __get__ me

Re: Make staticmethod objects callable?

2006-03-01 Thread Terry Reedy
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > >>> class Parrot: > ... def speak(): > ... return "dead parrot" > ... speak = staticmethod(speak) > ... def playdead(): > ... return "still dead" > ... > >>> type(Parrot.speak) > >

Re: Make staticmethod objects callable?

2006-03-01 Thread Nicolas Fleury
Steven Bethard wrote: > ... > Yes, you have to explain descriptors, but at the point that you start > trying to do funny things with staticmethods and classmethods, I think > you need to start learning about them anyway.) That's all good points, but IMHO, descriptors are a much more advanced Py

Re: Make staticmethod objects callable?

2006-03-01 Thread Steven Bethard
Steven D'Aprano wrote: > So, based on this evidence, staticmethod() inside a class definition > converts instance methods to functions. Outside a class definition, > staticmethod() does one of two things: it either converts an instance > method to a static method, or if the output is assigned to

Re: Make staticmethod objects callable?

2006-03-01 Thread Steven D'Aprano
Nicolas Fleury wrote: > Hi everyone, > I was wondering if it would make sense to make staticmethod objects > callable, so that the following code would work: This is one of the more unintuitive areas of Python, with side effects and different behaviour depending on whether code

Re: Make staticmethod objects callable?

2006-02-28 Thread Murali
You have a text-database, each record has some "header info" and some data (text-blob). e.g. name = "Tom" phone = "312-996-" I last met tom in 1998. He was still single then. blah blah name = "John" birthday = "1976-Mar-12" I need to ask him his email when I see him ne

Re: Make staticmethod objects callable?

2006-02-28 Thread Nicolas Fleury
Steven Bethard wrote: > Nicolas Fleury wrote: > >> I was wondering if it would make sense to make staticmethod objects >> callable, so that the following code would work: >> >> class A: >> @staticmethod >> def foo(): pass >> bar =

Re: Make staticmethod objects callable?

2006-02-28 Thread Nicolas Fleury
Felipe Almeida Lessa wrote: > Em Ter, 2006-02-28 às 15:17 -0500, Nicolas Fleury escreveu: > >>class A: >> @staticmethod >> def foo(): pass >> bar = foo() > > > # Why not: > > def foo(): pass > > class A: > bar = foo() > foo = staticmethod(foo) > Well, you could even d

Re: Make staticmethod objects callable?

2006-02-28 Thread Felipe Almeida Lessa
Em Ter, 2006-02-28 às 15:17 -0500, Nicolas Fleury escreveu: > class A: > @staticmethod > def foo(): pass > bar = foo() # Why not: def foo(): pass class A: bar = foo() foo = staticmethod(foo) -- "Quem excele em empregar a força militar subjulga os exércitos dos ou

Re: Make staticmethod objects callable?

2006-02-28 Thread Steven Bethard
Nicolas Fleury wrote: > I was wondering if it would make sense to make staticmethod objects > callable, so that the following code would work: > > class A: > @staticmethod > def foo(): pass > bar = foo() Do you have a real-world use case? I pretty much nev

Make staticmethod objects callable?

2006-02-28 Thread Nicolas Fleury
Hi everyone, I was wondering if it would make sense to make staticmethod objects callable, so that the following code would work: class A: @staticmethod def foo(): pass bar = foo() I understand staticmethod objects don't need to implement __call__ for their other use cases