[C++-sig] RE: static methods

David Abrahams dave at boost-consulting.com
Sun Jan 12 14:58:20 CET 2003

"Paul F Dubois" <paul at pfdubois.com> writes:

> I found it hard to read the thread due to html embedded in my digest, but
> one thing I did notice was that in Python you did not have your class C
> inherit from object. If you use property, staticmethod, or classmethod in an
> old-style class, they work but they don't work, if you get my drift. They
> execute at class compile time but don't function properly.

Can you show an example where that's the case?  It seems to work just
fine AFAICT:

    >>> class C:
    ...     def f(x,y):
    ...             return x+y
    ...     f = staticmethod(f)
    >>> C.f(2,3)
    >>> C().f(2,3)

> Here is a correct example. I hope this is the source of your
> difficulty.

<snip version with C inheriting from object>

It wouldn't be an issue for Boost.Python extension classes anyway,
since they are all derived from object.

> Note that the call to staticmethod is at the same level of
> indentation as the def f. This happens during class definition.
> Moral: metaclasses make your head explode.

This has nothing to do with metaclasses, though.  It's all about

What's so conceptually difficult about metaclasses?  With all due
respect, I think "metaclasses make your head explode" is in general a
bad lesson for people to learn and we should stop promulgating it.  It
leads to misapprehensions like the one you show above, that any
seemingly mysterious behavior has to do with metaclasses.

                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

More information about the Cplusplus-sig mailing list