Re: Make staticmethod objects callable?



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 never use staticmethods (preferring instead to use module-level functions) so I'm having a hard time coming up with some code where this would be really useful. I'm also a little wary of breaking the parallel between classmethod and staticmethod which are currently *just* descriptors (without any other special functionality).

Maybe instead of making just staticmethods callable, both staticmethods and classmethods could gain an 'im_func' attribute like bound and unbound methods have?

STeVe
.



Relevant Pages

  • Re: Method behavior for user-created class instances
    ... I am looking for a way to achieve method behavior for a class I ... class foo: ... If not, take a look at staticmethods or classmethods, they might work for you. ...
    (comp.lang.python)
  • Re: empty classes as c structs?
    ... Alex Martelli wrote: ... How would you design them as classmethods...? ... The classmethod would have to be called with an instance, ... these could be staticmethods instead since they don't need ...
    (comp.lang.python)