staticmethod
Andrew Bennetts
andrew-pythonlist at puzzling.org
Tue Feb 25 20:36:43 EST 2003
On Tue, Feb 25, 2003 at 04:36:53PM -0800, Erik Max Francis wrote:
> Jeremy Yallop wrote:
>
> > I find staticmethod()'s behaviour a bit surprising. In particular:
> >
> > Why does staticmethod() `work' on uncallable objects?
> >
> > >>> staticmethod('huh?')
> > <staticmethod object at 0x8152eb8>
> >
> > I'd expect this to raise an exception.
>
> staticmethod just creates a wrapper. It doesn't check whether the
> object in question is callable since Python is dynamic and, when passed
> arbitrary objects, it's not trivial to tell whether the object is
> callable unless you actually try calling it (and see if it fails). In
> other words, Python gives you the benefit of the doubt and supposes you
> know what you're doing.
Minor correction: it *is* trivial to tell if something is callable. Just do
"callable(something)".
-Andrew.
More information about the Python-list
mailing list