Mysterious argument count error to __new__

Clarence clarence1126 at gmail.com
Tue Apr 10 20:23:02 CEST 2007


I'm having problems with JPype and am trying to change the way
it creates Python classes as proxies for Java classes and interfaces.
I'm trying to get around "inconsistent mro" problems, but in doing
so, I've run into a real mystery.

Here's the original code. It first makes a metaclass, then makes a
class using that metaclass.

##############
metaclass = type.__new__(type, name+"$$Static", tuple(meta_bases),
static_fields)
members['__metaclass__'] = metaclass
result =  type.__new__(metaclass, name, tuple(bases), members)
##############

I'm getting an error on the first call to __new__, but I want to see
if my "bases" list is acceptable, putting aside for the moment that
"meta_bases" is having a problem.

So I put this line directly ahead of the three quoted above:
##############
type.__new__(type, 'aoeu', tuple(bases), members)
##############
You can see that this is essentially exactly the same as the first of
the three, just using a different name, a diffent bases tuple, and a
different dictionary. Whereas the first of the three gets an mro kind
of error, when I insert this new line, it gets:
    type.__new__(type, 'aoeu', tuple(bases), members)
     TypeError: __new__() takes exactly 2 arguments (4 given)

How is it possible that I get a number-of-arguments error when the
following line, with the same number of arguments, does not?
(This can't even be relevant, really, but I also printed out the
value of "type" before the line, and got <type 'type'> as it should
be.)

Thanks for any help.
Clarence




More information about the Python-list mailing list