[Python-Dev] Making staticmethod objects callable?

Guido van Rossum guido at python.org
Thu Mar 2 20:24:59 CET 2006

On 3/1/06, Nicolas Fleury <nidoizo at yahoo.com> wrote:
> Guido van Rossum wrote:
> > In which context did you find a need for defining a static method and
> > calling it inside the class definition? I'm guessing that what you're
> > playing dubious scoping games.
> I'm not.  I almost never use staticmethod actually.  I find them not
> very pythonic, in my humble own definition of pythonic.
> But since staticmethod is a standard built-in, I considered valid the
> question of a programmer relatively new to Python (but obviously
> appreciating its dynamic nature) wondering why calling a static method
> inside a class definition doesn't work.  A use case is not hard to
> imagine, especially a private static method called only to build a class
> attribute.

Imagined use cases aren't particularly interesting.

As to the "why" question, the answer is simply that it wasn't
considered an important use case since nobody could come up with a
reason why you'd want to do that apart from exploring the language.

> I don't know the philosophy behind making staticmethod a built-in
> (instead of a function in a module only used in specific occasions), but
> my guess was that what is normal scoping/regrouping in Java/C++/C# was
> worth common use support in Python.  But your comment about "dubious
> scoping games" makes me think I, again, didn't guess right;)

At the time there wasn't much thought about it -- it just seemed
reasonable to support something that was supported by syntax in other
languages with at least a built-in decorator in Python.

> So yes, I'm proposing something I'll probably never use, but I think
> would make Python more "welcoming".

I don't see how adding featuers that nobody uses helps.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list