Misleading Python error message

B

Brian Kelley

I accidentally derived a class from a module (types instead of
types.Dicttype)
....
Traceback (most recent call last):
File "<stdin>", line 1, in ?
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 :)

Brian
 
D

Dennis Lee Bieber

Brian Kelley fed this fish to the penguins on Wednesday 19 November
2003 12:02 pm:

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 :)
Which version?

Python 2.2 (#1, Nov 5 2002, 15:43:24)
[GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux-i386
Type "help", "copyright", "credits" or "license" for more information..... pass
....
class f(types): pass ....

dir(f) []
t = f()
Traceback (most recent call last):

--
 
A

Andrew Dalke

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
(e-mail address removed)
 
P

Peter Hansen

Dennis said:
Brian Kelley fed this fish to the penguins on Wednesday 19 November
2003 12:02 pm:

Which version?

Python 2.3, of course, as a result of the new types stuff.

-Peter
 
D

Dennis Lee Bieber

Peter Hansen fed this fish to the penguins on Thursday 20 November 2003
06:14 am:
Python 2.3, of course, as a result of the new types stuff.
Ah.. new behavior, then...

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,927
Members
47,469
Latest member
benny001

Latest Threads

Top