Misleading Python error message

Andrew Dalke adalke at mindspring.com
Thu Nov 20 04:02:13 EST 2003


Brian Kelley:
> I accidentally derived a class from a module (types instead of
> types.Dicttype)
 ...
> TypeError: function takes at most 2 arguments (3 given)
>
> Shouldn't this report something like (TypeError: can't subclass from a
> module)  It goes to the right line, but I coudn't see where the function
> was being called :)

Strangely enough, I asked this question last week, titled "class with
invalid base class".   (Strange because Brian and I used to work
together but there's no causation for this correlation in questions.)

Merging answers from Thomas Heller and Michael Hudson

  If the type(base class) is callable, which is true for all type objects
  since 2.2, then it's called with three arguments: The name of
  the new class, a tuple of the bases, and a dictionary.

However, ModuleType only takes two parameters, not three,
hence the TypeError.

I completely agree that the error message is inexplicable to all
but those whose heads have exploded.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list