Misleading Python error message

Discussion in 'Python' started by Brian Kelley, Nov 19, 2003.

  1. Brian Kelley

    Brian Kelley Guest

    I accidentally derived a class from a module (types instead of
    types.Dicttype)

    >>> import types
    >>> class f(types): pass

    ....
    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
    Brian Kelley, Nov 19, 2003
    #1
    1. Advertising

  2. 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.
    >>> import types
    >>> class f(types):

    .... pass
    ....
    >>> class f(types): pass

    ....
    >>>
    >>> dir(f)

    []
    >>> t = f()

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    TypeError: 'module' object is not callable
    >>>


    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Bestiaria Home Page: http://www.beastie.dm.net/ <
    > Home Page: http://www.dm.net/~wulfraed/ <
    Dennis Lee Bieber, Nov 20, 2003
    #2
    1. Advertising

  3. Brian Kelley

    Andrew Dalke Guest

    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
    Andrew Dalke, Nov 20, 2003
    #3
  4. Brian Kelley

    Peter Hansen Guest

    Dennis Lee Bieber wrote:
    >
    > 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.3, of course, as a result of the new types stuff.

    -Peter
    Peter Hansen, Nov 20, 2003
    #4
  5. 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...

    --
    > ============================================================== <
    > | Wulfraed Dennis Lee Bieber KD6MOG <
    > | Bestiaria Support Staff <
    > ============================================================== <
    > Bestiaria Home Page: http://www.beastie.dm.net/ <
    > Home Page: http://www.dm.net/~wulfraed/ <
    Dennis Lee Bieber, Nov 21, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. j
    Replies:
    5
    Views:
    403
    Samuel Barber
    Jul 27, 2003
  2. Claudio Grondi
    Replies:
    8
    Views:
    778
    Georg Brandl
    Aug 28, 2006
  3. Erik Johnson
    Replies:
    4
    Views:
    342
  4. John J. Lee
    Replies:
    27
    Views:
    605
  5. Roy Smith

    Misleading error message of the day

    Roy Smith, Dec 8, 2011, in forum: Python
    Replies:
    37
    Views:
    527
    Lie Ryan
    Dec 10, 2011
Loading...

Share This Page