Mixing metaclasses and exceptions

Alex Martelli aleaxit at yahoo.com
Fri Dec 31 13:18:23 EST 2004


Phillip J. Eby <pje at telecommunity.com> wrote:

> Jp Calderone wrote:
> >   I'd skip that, though.  Your problem doesn't sound "Metaclass!" at
> me.
> > I wonder if you could elaborate on your usage?  Perhaps there's a
> better
> > solution which doesn't involve metaclasses at all.
> 
> I suspect he could *maybe* get by without the metaclass, but not
> without custom descriptors, which don't always work for classic
> classes.  In particular, if a Java exception has a static method, he'll
> want to map that to a Python classmethod or staticmethod, and as far as
> I recall, that stuff just doesn't work with classic classes.

I believe they work fine:

>>> class sic: 
...   @staticmethod
...   def hello(): print "Hello world"
... 
>>> sic.hello()
Hello world


Class-sick classes have many little niggling problems, but I think
staticmethod and classmethod aren't among them.


> In particular, if a Java class has both a static method and a
> non-static method of the same name, there's no way that I know of to
> map it into Python using a classic class; you *have* to have a
> metaclass with a data descriptor in order to prevent a __dict__ lookup
> on the class itself.

Well, that's another ball of wax.  Does Java support that kind of
overloading...?!  Eeek.  I believe C++ doesn't and for once is simpler
thereby.


Alex



More information about the Python-list mailing list